Skip to content

Commit

Permalink
Change clientID type from bytes to string in the API
Browse files Browse the repository at this point in the history
  • Loading branch information
chacha912 committed Aug 18, 2023
1 parent 3b82977 commit d7a743b
Show file tree
Hide file tree
Showing 7 changed files with 322 additions and 342 deletions.
346 changes: 172 additions & 174 deletions api/yorkie/v1/resources.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/yorkie/v1/resources.proto
Original file line number Diff line number Diff line change
Expand Up @@ -360,5 +360,5 @@ enum DocEventType {

message DocEvent {
DocEventType type = 1;
bytes publisher = 2;
string publisher = 2;
}
244 changes: 115 additions & 129 deletions api/yorkie/v1/yorkie.pb.go

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions api/yorkie/v1/yorkie.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ message ActivateClientRequest {
}

message ActivateClientResponse {
bytes client_id = 1;
string client_id = 1;
}

message DeactivateClientRequest {
bytes client_id = 1;
string client_id = 1;
}

message DeactivateClientResponse {
}

message AttachDocumentRequest {
bytes client_id = 1;
string client_id = 1;
ChangePack change_pack = 2;
}

Expand All @@ -63,7 +63,7 @@ message AttachDocumentResponse {
}

message DetachDocumentRequest {
bytes client_id = 1;
string client_id = 1;
string document_id = 2;
ChangePack change_pack = 3;
bool remove_if_not_attached = 4;
Expand All @@ -74,13 +74,13 @@ message DetachDocumentResponse {
}

message WatchDocumentRequest {
bytes client_id = 1;
string client_id = 1;
string document_id = 2;
}

message WatchDocumentResponse {
message Initialization {
repeated bytes client_ids = 1;
repeated string client_ids = 1;
}

oneof body {
Expand All @@ -90,7 +90,7 @@ message WatchDocumentResponse {
}

message RemoveDocumentRequest {
bytes client_id = 1;
string client_id = 1;
string document_id = 2;
ChangePack change_pack = 3;
}
Expand All @@ -100,7 +100,7 @@ message RemoveDocumentResponse {
}

message PushPullChangesRequest {
bytes client_id = 1;
string client_id = 1;
string document_id = 2;
ChangePack change_pack = 3;
bool push_only = 4;
Expand Down
18 changes: 9 additions & 9 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (c *Client) Activate(ctx context.Context) error {
return err
}

clientID, err := time.ActorIDFromBytes(response.ClientId)
clientID, err := time.ActorIDFromHex(response.ClientId)
if err != nil {
return err
}
Expand All @@ -232,7 +232,7 @@ func (c *Client) Deactivate(ctx context.Context) error {
}

_, err := c.client.DeactivateClient(withShardKey(ctx, c.options.APIKey), &api.DeactivateClientRequest{
ClientId: c.id.Bytes(),
ClientId: c.id.String(),
})
if err != nil {
return err
Expand Down Expand Up @@ -276,7 +276,7 @@ func (c *Client) Attach(ctx context.Context, doc *document.Document, options ...
res, err := c.client.AttachDocument(
withShardKey(ctx, c.options.APIKey, doc.Key().String()),
&api.AttachDocumentRequest{
ClientId: c.id.Bytes(),
ClientId: c.id.String(),
ChangePack: pbChangePack,
},
)
Expand Down Expand Up @@ -349,7 +349,7 @@ func (c *Client) Detach(ctx context.Context, doc *document.Document, options ...
res, err := c.client.DetachDocument(
withShardKey(ctx, c.options.APIKey, doc.Key().String()),
&api.DetachDocumentRequest{
ClientId: c.id.Bytes(),
ClientId: c.id.String(),
DocumentId: attachment.docID.String(),
ChangePack: pbChangePack,
RemoveIfNotAttached: opts.removeIfNotAttached,
Expand Down Expand Up @@ -412,7 +412,7 @@ func (c *Client) Watch(
stream, err := c.client.WatchDocument(
withShardKey(ctx, c.options.APIKey, doc.Key().String()),
&api.WatchDocumentRequest{
ClientId: c.id.Bytes(),
ClientId: c.id.String(),
DocumentId: attachment.docID.String(),
},
)
Expand All @@ -425,7 +425,7 @@ func (c *Client) Watch(
case *api.WatchDocumentResponse_Initialization_:
var clientIDs []string
for _, clientID := range resp.Initialization.ClientIds {
id, err := time.ActorIDFromBytes(clientID)
id, err := time.ActorIDFromHex(clientID)
if err != nil {
return nil, err
}
Expand All @@ -440,7 +440,7 @@ func (c *Client) Watch(
return nil, err
}

cli, err := time.ActorIDFromBytes(resp.Event.Publisher)
cli, err := time.ActorIDFromHex(resp.Event.Publisher)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -581,7 +581,7 @@ func (c *Client) pushPullChanges(ctx context.Context, opt SyncOptions) error {
res, err := c.client.PushPullChanges(
withShardKey(ctx, c.options.APIKey, opt.key.String()),
&api.PushPullChangesRequest{
ClientId: c.id.Bytes(),
ClientId: c.id.String(),
DocumentId: attachment.docID.String(),
ChangePack: pbChangePack,
PushOnly: opt.mode == types.SyncModePushOnly,
Expand Down Expand Up @@ -626,7 +626,7 @@ func (c *Client) Remove(ctx context.Context, doc *document.Document) error {
res, err := c.client.RemoveDocument(
withShardKey(ctx, c.options.APIKey, doc.Key().String()),
&api.RemoveDocumentRequest{
ClientId: c.id.Bytes(),
ClientId: c.id.String(),
DocumentId: attachment.docID.String(),
ChangePack: pbChangePack,
},
Expand Down
13 changes: 7 additions & 6 deletions server/rpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ var (
defaultProjectName = "default"
invalidSlugName = "@#$%^&*()_+"

nilClientID, _ = hex.DecodeString("000000000000000000000000")
emptyClientID, _ = hex.DecodeString("")
invalidClientID, _ = hex.DecodeString("invalid")
nilClientID = "000000000000000000000000"
emptyClientID = ""
invalidClientID = "invalid"

testRPCServer *rpc.Server
testRPCAddr = fmt.Sprintf("localhost:%d", helper.RPCPort)
Expand Down Expand Up @@ -387,6 +387,7 @@ func TestSDKRPCServerBackend(t *testing.T) {
)
assert.NoError(t, err)

actorID, _ := hex.DecodeString(activateResp.ClientId)
resPack, err := testClient.AttachDocument(
context.Background(),
&api.AttachDocumentRequest{
Expand All @@ -398,7 +399,7 @@ func TestSDKRPCServerBackend(t *testing.T) {
Id: &api.ChangeID{
ClientSeq: 1,
Lamport: 1,
ActorId: activateResp.ClientId,
ActorId: actorID,
},
}},
},
Expand All @@ -418,7 +419,7 @@ func TestSDKRPCServerBackend(t *testing.T) {
Id: &api.ChangeID{
ClientSeq: 2,
Lamport: 2,
ActorId: activateResp.ClientId,
ActorId: actorID,
},
}},
},
Expand All @@ -438,7 +439,7 @@ func TestSDKRPCServerBackend(t *testing.T) {
Id: &api.ChangeID{
ClientSeq: 3,
Lamport: 3,
ActorId: activateResp.ClientId,
ActorId: actorID,
},
}},
},
Expand Down
25 changes: 10 additions & 15 deletions server/rpc/yorkie_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,8 @@ func (s *yorkieServer) ActivateClient(
return nil, err
}

pbClientID, err := cli.ID.Bytes()
if err != nil {
return nil, err
}

return &api.ActivateClientResponse{
ClientId: pbClientID,
ClientId: cli.ID.String(),
}, nil
}

Expand All @@ -84,7 +79,7 @@ func (s *yorkieServer) DeactivateClient(
ctx context.Context,
req *api.DeactivateClientRequest,
) (*api.DeactivateClientResponse, error) {
actorID, err := time.ActorIDFromBytes(req.ClientId)
actorID, err := time.ActorIDFromHex(req.ClientId)
if err != nil {
return nil, err
}
Expand All @@ -109,7 +104,7 @@ func (s *yorkieServer) AttachDocument(
ctx context.Context,
req *api.AttachDocumentRequest,
) (*api.AttachDocumentResponse, error) {
actorID, err := time.ActorIDFromBytes(req.ClientId)
actorID, err := time.ActorIDFromHex(req.ClientId)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -178,7 +173,7 @@ func (s *yorkieServer) DetachDocument(
ctx context.Context,
req *api.DetachDocumentRequest,
) (*api.DetachDocumentResponse, error) {
actorID, err := time.ActorIDFromBytes(req.ClientId)
actorID, err := time.ActorIDFromHex(req.ClientId)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -260,7 +255,7 @@ func (s *yorkieServer) PushPullChanges(
ctx context.Context,
req *api.PushPullChangesRequest,
) (*api.PushPullChangesResponse, error) {
actorID, err := time.ActorIDFromBytes(req.ClientId)
actorID, err := time.ActorIDFromHex(req.ClientId)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -340,7 +335,7 @@ func (s *yorkieServer) WatchDocument(
req *api.WatchDocumentRequest,
stream api.YorkieService_WatchDocumentServer,
) error {
clientID, err := time.ActorIDFromBytes(req.ClientId)
clientID, err := time.ActorIDFromHex(req.ClientId)
if err != nil {
return err
}
Expand Down Expand Up @@ -396,9 +391,9 @@ func (s *yorkieServer) WatchDocument(
s.unwatchDoc(subscription, docID)
}()

var pbClientIDs [][]byte
var pbClientIDs []string
for _, id := range clientIDs {
pbClientIDs = append(pbClientIDs, id.Bytes())
pbClientIDs = append(pbClientIDs, id.String())
}
if err := stream.Send(&api.WatchDocumentResponse{
Body: &api.WatchDocumentResponse_Initialization_{
Expand Down Expand Up @@ -426,7 +421,7 @@ func (s *yorkieServer) WatchDocument(
Body: &api.WatchDocumentResponse_Event{
Event: &api.DocEvent{
Type: eventType,
Publisher: event.Publisher.Bytes(),
Publisher: event.Publisher.String(),
},
},
}); err != nil {
Expand All @@ -441,7 +436,7 @@ func (s *yorkieServer) RemoveDocument(
ctx context.Context,
req *api.RemoveDocumentRequest,
) (*api.RemoveDocumentResponse, error) {
actorID, err := time.ActorIDFromBytes(req.ClientId)
actorID, err := time.ActorIDFromHex(req.ClientId)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit d7a743b

Please sign in to comment.