actorid.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. #include "actorid.h"
  2. #include <util/string/builder.h>
  3. #include <util/string/cast.h>
  4. namespace NActors {
  5. void TActorId::Out(IOutputStream& o) const {
  6. o << "[" << NodeId() << ":" << LocalId() << ":" << Hint() << "]";
  7. }
  8. TString TActorId::ToString() const {
  9. TString x;
  10. TStringOutput o(x);
  11. Out(o);
  12. return x;
  13. }
  14. bool TActorId::Parse(const char* buf, ui32 sz) {
  15. if (sz < 4 || buf[0] != '[' || buf[sz - 1] != ']')
  16. return false;
  17. size_t semicolons[2];
  18. TStringBuf str(buf, sz);
  19. semicolons[0] = str.find(':', 1);
  20. if (semicolons[0] == TStringBuf::npos)
  21. return false;
  22. semicolons[1] = str.find(':', semicolons[0] + 1);
  23. if (semicolons[1] == TStringBuf::npos)
  24. return false;
  25. bool success = TryFromString(buf + 1, semicolons[0] - 1, Raw.N.NodeId) && TryFromString(buf + semicolons[0] + 1, semicolons[1] - semicolons[0] - 1, Raw.N.LocalId) && TryFromString(buf + semicolons[1] + 1, sz - semicolons[1] - 2, Raw.N.Hint);
  26. return success;
  27. }
  28. }