diff --git a/testing/cmd/bankdemo/bank.go b/testing/cmd/bankdemo/bank.go index 88fce70..2971cc8 100644 --- a/testing/cmd/bankdemo/bank.go +++ b/testing/cmd/bankdemo/bank.go @@ -34,30 +34,7 @@ func (s *bankServer) OpenAccount(ctx context.Context, req *OpenAccountRequest) ( return nil, status.Errorf(codes.InvalidArgument, "invalid account type: %v", req.Type) } - s.allAccounts.mu.Lock() - defer s.allAccounts.mu.Unlock() - accountNums, ok := s.allAccounts.AccountNumbersByCustomer[cust] - if !ok { - // no accounts for this customer? it's a new customer - s.allAccounts.Customers = append(s.allAccounts.Customers, cust) - } - num := s.allAccounts.LastAccountNum + 1 - s.allAccounts.LastAccountNum = num - s.allAccounts.AccountNumbers = append(s.allAccounts.AccountNumbers, num) - accountNums = append(accountNums, num) - s.allAccounts.AccountNumbersByCustomer[cust] = accountNums - var acct account - acct.AccountNumber = num - acct.BalanceCents = req.InitialDepositCents - acct.Transactions = append(acct.Transactions, &Transaction{ - AccountNumber: num, - SeqNumber: 1, - Date: ptypes.TimestampNow(), - AmountCents: req.InitialDepositCents, - Desc: "initial deposit", - }) - s.allAccounts.AccountsByNumber[num] = &acct - return &acct.Account, nil + return s.allAccounts.openAccount(cust, req.Type, req.InitialDepositCents), nil } func (s *bankServer) CloseAccount(ctx context.Context, req *CloseAccountRequest) (*empty.Empty, error) { @@ -66,33 +43,9 @@ func (s *bankServer) CloseAccount(ctx context.Context, req *CloseAccountRequest) return nil, status.Error(codes.Unauthenticated, codes.Unauthenticated.String()) } - s.allAccounts.mu.Lock() - defer s.allAccounts.mu.Unlock() - acctNums := s.allAccounts.AccountNumbersByCustomer[cust] - found := -1 - for i, num := range acctNums { - if num == req.AccountNumber { - found = i - break - } + if err := s.allAccounts.closeAccount(cust, req.AccountNumber); err != nil { + return nil, err } - if found == -1 { - return nil, status.Errorf(codes.NotFound, "you have no account numbered %d", req.AccountNumber) - } - - for i, num := range s.allAccounts.AccountNumbers { - if num == req.AccountNumber { - s.allAccounts.AccountNumbers = append(s.allAccounts.AccountNumbers[:i], s.allAccounts.AccountNumbers[i+1:]...) - break - } - } - - acct := s.allAccounts.AccountsByNumber[req.AccountNumber] - if acct.BalanceCents != 0 { - return nil, status.Errorf(codes.FailedPrecondition, "account %d cannot be closed because it has a non-zero balance: %s", req.AccountNumber, dollars(acct.BalanceCents)) - } - s.allAccounts.AccountNumbersByCustomer[cust] = append(acctNums[:found], acctNums[found+1:]...) - delete(s.allAccounts.AccountsByNumber, req.AccountNumber) return &empty.Empty{}, nil } @@ -102,13 +55,7 @@ func (s *bankServer) GetAccounts(ctx context.Context, _ *empty.Empty) (*GetAccou return nil, status.Error(codes.Unauthenticated, codes.Unauthenticated.String()) } - s.allAccounts.mu.RLock() - defer s.allAccounts.mu.RUnlock() - accountNums := s.allAccounts.AccountNumbersByCustomer[cust] - var accounts []*Account - for _, num := range accountNums { - accounts = append(accounts, &s.allAccounts.AccountsByNumber[num].Account) - } + accounts := s.allAccounts.getAllAccounts(cust) return &GetAccountsResponse{Accounts: accounts}, nil } @@ -118,17 +65,7 @@ func (s *bankServer) GetTransactions(req *GetTransactionsRequest, stream Bank_Ge return status.Error(codes.Unauthenticated, codes.Unauthenticated.String()) } - acct, err := func() (*account, error) { - s.allAccounts.mu.Lock() - defer s.allAccounts.mu.Unlock() - acctNums := s.allAccounts.AccountNumbersByCustomer[cust] - for _, num := range acctNums { - if num == req.AccountNumber { - return s.allAccounts.AccountsByNumber[num], nil - } - } - return nil, status.Errorf(codes.NotFound, "you have no account numbered %d", req.AccountNumber) - }() + acct, err := s.allAccounts.getAccount(cust, req.AccountNumber) if err != nil { return err } @@ -149,10 +86,7 @@ func (s *bankServer) GetTransactions(req *GetTransactionsRequest, stream Bank_Ge end = time.Date(9999, 12, 31, 23, 59, 59, 999999999, time.Local) } - acct.mu.RLock() - txns := acct.Transactions - acct.mu.RUnlock() - + txns := acct.getTransactions() for _, txn := range txns { t, err := ptypes.Timestamp(txn.Date) if err != nil { @@ -190,7 +124,11 @@ func (s *bankServer) Deposit(ctx context.Context, req *DepositRequest) (*Balance if req.Desc != "" { desc = fmt.Sprintf("%s: %s", desc, req.Desc) } - newBalance, err := s.newTransaction(cust, req.AccountNumber, req.AmountCents, desc) + acct, err := s.allAccounts.getAccount(cust, req.AccountNumber) + if err != nil { + return nil, err + } + newBalance, err := acct.newTransaction(req.AmountCents, desc) if err != nil { return nil, err } @@ -200,26 +138,6 @@ func (s *bankServer) Deposit(ctx context.Context, req *DepositRequest) (*Balance }, nil } -func (s *bankServer) getAccount(cust string, acctNumber uint64) (*account, error) { - s.allAccounts.mu.Lock() - defer s.allAccounts.mu.Unlock() - acctNums := s.allAccounts.AccountNumbersByCustomer[cust] - for _, num := range acctNums { - if num == acctNumber { - return s.allAccounts.AccountsByNumber[num], nil - } - } - return nil, status.Errorf(codes.NotFound, "you have no account numbered %d", acctNumber) -} - -func (s *bankServer) newTransaction(cust string, acctNumber uint64, amountCents int32, desc string) (int32, error) { - acct, err := s.getAccount(cust, acctNumber) - if err != nil { - return 0, err - } - return acct.newTransaction(amountCents, desc) -} - func (s *bankServer) Withdraw(ctx context.Context, req *WithdrawRequest) (*BalanceResponse, error) { cust := getCustomer(ctx) if cust == "" { @@ -230,7 +148,11 @@ func (s *bankServer) Withdraw(ctx context.Context, req *WithdrawRequest) (*Balan return nil, status.Errorf(codes.InvalidArgument, "withdrawal amount cannot be non-negative: %s", dollars(req.AmountCents)) } - newBalance, err := s.newTransaction(cust, req.AccountNumber, req.AmountCents, req.Desc) + acct, err := s.allAccounts.getAccount(cust, req.AccountNumber) + if err != nil { + return nil, err + } + newBalance, err := acct.newTransaction(req.AmountCents, req.Desc) if err != nil { return nil, err } @@ -240,10 +162,6 @@ func (s *bankServer) Withdraw(ctx context.Context, req *WithdrawRequest) (*Balan }, nil } -func dollars(amountCents int32) string { - return fmt.Sprintf("$%02f", float64(amountCents)/100) -} - func (s *bankServer) Transfer(ctx context.Context, req *TransferRequest) (*TransferResponse, error) { cust := getCustomer(ctx) if cust == "" { @@ -265,7 +183,7 @@ func (s *bankServer) Transfer(ctx context.Context, req *TransferRequest) (*Trans case *TransferRequest_SourceAccountNumber: srcDesc = fmt.Sprintf("account %06d", src.SourceAccountNumber) var err error - if srcAcct, err = s.getAccount(cust, src.SourceAccountNumber); err != nil { + if srcAcct, err = s.allAccounts.getAccount(cust, src.SourceAccountNumber); err != nil { return nil, err } } @@ -281,7 +199,7 @@ func (s *bankServer) Transfer(ctx context.Context, req *TransferRequest) (*Trans case *TransferRequest_DestAccountNumber: destDesc = fmt.Sprintf("account %06d", dest.DestAccountNumber) var err error - if destAcct, err = s.getAccount(cust, dest.DestAccountNumber); err != nil { + if destAcct, err = s.allAccounts.getAccount(cust, dest.DestAccountNumber); err != nil { return nil, err } } diff --git a/testing/cmd/bankdemo/bank.pb.go b/testing/cmd/bankdemo/bank.pb.go index a645779..c5fe017 100644 --- a/testing/cmd/bankdemo/bank.pb.go +++ b/testing/cmd/bankdemo/bank.pb.go @@ -25,26 +25,6 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package -type Void int32 - -const ( - Void_VOID Void = 0 -) - -var Void_name = map[int32]string{ - 0: "VOID", -} -var Void_value = map[string]int32{ - "VOID": 0, -} - -func (x Void) String() string { - return proto.EnumName(Void_name, int32(x)) -} -func (Void) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_bank_a8a0edd183099ef5, []int{0} -} - type Account_Type int32 const ( @@ -80,7 +60,7 @@ func (x Account_Type) String() string { return proto.EnumName(Account_Type_name, int32(x)) } func (Account_Type) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_bank_a8a0edd183099ef5, []int{3, 0} + return fileDescriptor_bank_485eb966c3eae5d1, []int{3, 0} } type DepositRequest_Source int32 @@ -112,7 +92,7 @@ func (x DepositRequest_Source) String() string { return proto.EnumName(DepositRequest_Source_name, int32(x)) } func (DepositRequest_Source) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_bank_a8a0edd183099ef5, []int{6, 0} + return fileDescriptor_bank_485eb966c3eae5d1, []int{6, 0} } type OpenAccountRequest struct { @@ -127,7 +107,7 @@ func (m *OpenAccountRequest) Reset() { *m = OpenAccountRequest{} } func (m *OpenAccountRequest) String() string { return proto.CompactTextString(m) } func (*OpenAccountRequest) ProtoMessage() {} func (*OpenAccountRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_bank_a8a0edd183099ef5, []int{0} + return fileDescriptor_bank_485eb966c3eae5d1, []int{0} } func (m *OpenAccountRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_OpenAccountRequest.Unmarshal(m, b) @@ -172,7 +152,7 @@ func (m *CloseAccountRequest) Reset() { *m = CloseAccountRequest{} } func (m *CloseAccountRequest) String() string { return proto.CompactTextString(m) } func (*CloseAccountRequest) ProtoMessage() {} func (*CloseAccountRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_bank_a8a0edd183099ef5, []int{1} + return fileDescriptor_bank_485eb966c3eae5d1, []int{1} } func (m *CloseAccountRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_CloseAccountRequest.Unmarshal(m, b) @@ -210,7 +190,7 @@ func (m *GetAccountsResponse) Reset() { *m = GetAccountsResponse{} } func (m *GetAccountsResponse) String() string { return proto.CompactTextString(m) } func (*GetAccountsResponse) ProtoMessage() {} func (*GetAccountsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_bank_a8a0edd183099ef5, []int{2} + return fileDescriptor_bank_485eb966c3eae5d1, []int{2} } func (m *GetAccountsResponse) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_GetAccountsResponse.Unmarshal(m, b) @@ -250,7 +230,7 @@ func (m *Account) Reset() { *m = Account{} } func (m *Account) String() string { return proto.CompactTextString(m) } func (*Account) ProtoMessage() {} func (*Account) Descriptor() ([]byte, []int) { - return fileDescriptor_bank_a8a0edd183099ef5, []int{3} + return fileDescriptor_bank_485eb966c3eae5d1, []int{3} } func (m *Account) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Account.Unmarshal(m, b) @@ -304,7 +284,7 @@ func (m *GetTransactionsRequest) Reset() { *m = GetTransactionsRequest{} func (m *GetTransactionsRequest) String() string { return proto.CompactTextString(m) } func (*GetTransactionsRequest) ProtoMessage() {} func (*GetTransactionsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_bank_a8a0edd183099ef5, []int{4} + return fileDescriptor_bank_485eb966c3eae5d1, []int{4} } func (m *GetTransactionsRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_GetTransactionsRequest.Unmarshal(m, b) @@ -360,7 +340,7 @@ func (m *Transaction) Reset() { *m = Transaction{} } func (m *Transaction) String() string { return proto.CompactTextString(m) } func (*Transaction) ProtoMessage() {} func (*Transaction) Descriptor() ([]byte, []int) { - return fileDescriptor_bank_a8a0edd183099ef5, []int{5} + return fileDescriptor_bank_485eb966c3eae5d1, []int{5} } func (m *Transaction) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Transaction.Unmarshal(m, b) @@ -429,7 +409,7 @@ func (m *DepositRequest) Reset() { *m = DepositRequest{} } func (m *DepositRequest) String() string { return proto.CompactTextString(m) } func (*DepositRequest) ProtoMessage() {} func (*DepositRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_bank_a8a0edd183099ef5, []int{6} + return fileDescriptor_bank_485eb966c3eae5d1, []int{6} } func (m *DepositRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_DepositRequest.Unmarshal(m, b) @@ -489,7 +469,7 @@ func (m *BalanceResponse) Reset() { *m = BalanceResponse{} } func (m *BalanceResponse) String() string { return proto.CompactTextString(m) } func (*BalanceResponse) ProtoMessage() {} func (*BalanceResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_bank_a8a0edd183099ef5, []int{7} + return fileDescriptor_bank_485eb966c3eae5d1, []int{7} } func (m *BalanceResponse) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_BalanceResponse.Unmarshal(m, b) @@ -536,7 +516,7 @@ func (m *WithdrawRequest) Reset() { *m = WithdrawRequest{} } func (m *WithdrawRequest) String() string { return proto.CompactTextString(m) } func (*WithdrawRequest) ProtoMessage() {} func (*WithdrawRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_bank_a8a0edd183099ef5, []int{8} + return fileDescriptor_bank_485eb966c3eae5d1, []int{8} } func (m *WithdrawRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_WithdrawRequest.Unmarshal(m, b) @@ -597,7 +577,7 @@ func (m *TransferRequest) Reset() { *m = TransferRequest{} } func (m *TransferRequest) String() string { return proto.CompactTextString(m) } func (*TransferRequest) ProtoMessage() {} func (*TransferRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_bank_a8a0edd183099ef5, []int{9} + return fileDescriptor_bank_485eb966c3eae5d1, []int{9} } func (m *TransferRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_TransferRequest.Unmarshal(m, b) @@ -823,7 +803,7 @@ func (m *TransferRequest_ExternalAccount) Reset() { *m = TransferRequest func (m *TransferRequest_ExternalAccount) String() string { return proto.CompactTextString(m) } func (*TransferRequest_ExternalAccount) ProtoMessage() {} func (*TransferRequest_ExternalAccount) Descriptor() ([]byte, []int) { - return fileDescriptor_bank_a8a0edd183099ef5, []int{9, 0} + return fileDescriptor_bank_485eb966c3eae5d1, []int{9, 0} } func (m *TransferRequest_ExternalAccount) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_TransferRequest_ExternalAccount.Unmarshal(m, b) @@ -871,7 +851,7 @@ func (m *TransferResponse) Reset() { *m = TransferResponse{} } func (m *TransferResponse) String() string { return proto.CompactTextString(m) } func (*TransferResponse) ProtoMessage() {} func (*TransferResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_bank_a8a0edd183099ef5, []int{10} + return fileDescriptor_bank_485eb966c3eae5d1, []int{10} } func (m *TransferResponse) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_TransferResponse.Unmarshal(m, b) @@ -919,971 +899,6 @@ func (m *TransferResponse) GetDestBalanceCents() int32 { return 0 } -type ChatCustomerRequest struct { - // Types that are valid to be assigned to Req: - // *ChatCustomerRequest_Init - // *ChatCustomerRequest_Msg - // *ChatCustomerRequest_HangUp - Req isChatCustomerRequest_Req `protobuf_oneof:"req"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ChatCustomerRequest) Reset() { *m = ChatCustomerRequest{} } -func (m *ChatCustomerRequest) String() string { return proto.CompactTextString(m) } -func (*ChatCustomerRequest) ProtoMessage() {} -func (*ChatCustomerRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_bank_a8a0edd183099ef5, []int{11} -} -func (m *ChatCustomerRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ChatCustomerRequest.Unmarshal(m, b) -} -func (m *ChatCustomerRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ChatCustomerRequest.Marshal(b, m, deterministic) -} -func (dst *ChatCustomerRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_ChatCustomerRequest.Merge(dst, src) -} -func (m *ChatCustomerRequest) XXX_Size() int { - return xxx_messageInfo_ChatCustomerRequest.Size(m) -} -func (m *ChatCustomerRequest) XXX_DiscardUnknown() { - xxx_messageInfo_ChatCustomerRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_ChatCustomerRequest proto.InternalMessageInfo - -type isChatCustomerRequest_Req interface { - isChatCustomerRequest_Req() -} - -type ChatCustomerRequest_Init struct { - Init *InitiateChat `protobuf:"bytes,1,opt,name=init,proto3,oneof"` -} -type ChatCustomerRequest_Msg struct { - Msg string `protobuf:"bytes,2,opt,name=msg,proto3,oneof"` -} -type ChatCustomerRequest_HangUp struct { - HangUp Void `protobuf:"varint,3,opt,name=hang_up,json=hangUp,proto3,enum=Void,oneof"` -} - -func (*ChatCustomerRequest_Init) isChatCustomerRequest_Req() {} -func (*ChatCustomerRequest_Msg) isChatCustomerRequest_Req() {} -func (*ChatCustomerRequest_HangUp) isChatCustomerRequest_Req() {} - -func (m *ChatCustomerRequest) GetReq() isChatCustomerRequest_Req { - if m != nil { - return m.Req - } - return nil -} - -func (m *ChatCustomerRequest) GetInit() *InitiateChat { - if x, ok := m.GetReq().(*ChatCustomerRequest_Init); ok { - return x.Init - } - return nil -} - -func (m *ChatCustomerRequest) GetMsg() string { - if x, ok := m.GetReq().(*ChatCustomerRequest_Msg); ok { - return x.Msg - } - return "" -} - -func (m *ChatCustomerRequest) GetHangUp() Void { - if x, ok := m.GetReq().(*ChatCustomerRequest_HangUp); ok { - return x.HangUp - } - return Void_VOID -} - -// XXX_OneofFuncs is for the internal use of the proto package. -func (*ChatCustomerRequest) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { - return _ChatCustomerRequest_OneofMarshaler, _ChatCustomerRequest_OneofUnmarshaler, _ChatCustomerRequest_OneofSizer, []interface{}{ - (*ChatCustomerRequest_Init)(nil), - (*ChatCustomerRequest_Msg)(nil), - (*ChatCustomerRequest_HangUp)(nil), - } -} - -func _ChatCustomerRequest_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { - m := msg.(*ChatCustomerRequest) - // req - switch x := m.Req.(type) { - case *ChatCustomerRequest_Init: - b.EncodeVarint(1<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.Init); err != nil { - return err - } - case *ChatCustomerRequest_Msg: - b.EncodeVarint(2<<3 | proto.WireBytes) - b.EncodeStringBytes(x.Msg) - case *ChatCustomerRequest_HangUp: - b.EncodeVarint(3<<3 | proto.WireVarint) - b.EncodeVarint(uint64(x.HangUp)) - case nil: - default: - return fmt.Errorf("ChatCustomerRequest.Req has unexpected type %T", x) - } - return nil -} - -func _ChatCustomerRequest_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { - m := msg.(*ChatCustomerRequest) - switch tag { - case 1: // req.init - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(InitiateChat) - err := b.DecodeMessage(msg) - m.Req = &ChatCustomerRequest_Init{msg} - return true, err - case 2: // req.msg - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - x, err := b.DecodeStringBytes() - m.Req = &ChatCustomerRequest_Msg{x} - return true, err - case 3: // req.hang_up - if wire != proto.WireVarint { - return true, proto.ErrInternalBadWireType - } - x, err := b.DecodeVarint() - m.Req = &ChatCustomerRequest_HangUp{Void(x)} - return true, err - default: - return false, nil - } -} - -func _ChatCustomerRequest_OneofSizer(msg proto.Message) (n int) { - m := msg.(*ChatCustomerRequest) - // req - switch x := m.Req.(type) { - case *ChatCustomerRequest_Init: - s := proto.Size(x.Init) - n += 1 // tag and wire - n += proto.SizeVarint(uint64(s)) - n += s - case *ChatCustomerRequest_Msg: - n += 1 // tag and wire - n += proto.SizeVarint(uint64(len(x.Msg))) - n += len(x.Msg) - case *ChatCustomerRequest_HangUp: - n += 1 // tag and wire - n += proto.SizeVarint(uint64(x.HangUp)) - case nil: - default: - panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) - } - return n -} - -type InitiateChat struct { - ResumeSessionId string `protobuf:"bytes,1,opt,name=resume_session_id,json=resumeSessionId,proto3" json:"resume_session_id,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *InitiateChat) Reset() { *m = InitiateChat{} } -func (m *InitiateChat) String() string { return proto.CompactTextString(m) } -func (*InitiateChat) ProtoMessage() {} -func (*InitiateChat) Descriptor() ([]byte, []int) { - return fileDescriptor_bank_a8a0edd183099ef5, []int{12} -} -func (m *InitiateChat) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_InitiateChat.Unmarshal(m, b) -} -func (m *InitiateChat) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_InitiateChat.Marshal(b, m, deterministic) -} -func (dst *InitiateChat) XXX_Merge(src proto.Message) { - xxx_messageInfo_InitiateChat.Merge(dst, src) -} -func (m *InitiateChat) XXX_Size() int { - return xxx_messageInfo_InitiateChat.Size(m) -} -func (m *InitiateChat) XXX_DiscardUnknown() { - xxx_messageInfo_InitiateChat.DiscardUnknown(m) -} - -var xxx_messageInfo_InitiateChat proto.InternalMessageInfo - -func (m *InitiateChat) GetResumeSessionId() string { - if m != nil { - return m.ResumeSessionId - } - return "" -} - -type AgentMessage struct { - AgentName string `protobuf:"bytes,1,opt,name=agent_name,json=agentName,proto3" json:"agent_name,omitempty"` - Msg string `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *AgentMessage) Reset() { *m = AgentMessage{} } -func (m *AgentMessage) String() string { return proto.CompactTextString(m) } -func (*AgentMessage) ProtoMessage() {} -func (*AgentMessage) Descriptor() ([]byte, []int) { - return fileDescriptor_bank_a8a0edd183099ef5, []int{13} -} -func (m *AgentMessage) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_AgentMessage.Unmarshal(m, b) -} -func (m *AgentMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_AgentMessage.Marshal(b, m, deterministic) -} -func (dst *AgentMessage) XXX_Merge(src proto.Message) { - xxx_messageInfo_AgentMessage.Merge(dst, src) -} -func (m *AgentMessage) XXX_Size() int { - return xxx_messageInfo_AgentMessage.Size(m) -} -func (m *AgentMessage) XXX_DiscardUnknown() { - xxx_messageInfo_AgentMessage.DiscardUnknown(m) -} - -var xxx_messageInfo_AgentMessage proto.InternalMessageInfo - -func (m *AgentMessage) GetAgentName() string { - if m != nil { - return m.AgentName - } - return "" -} - -func (m *AgentMessage) GetMsg() string { - if m != nil { - return m.Msg - } - return "" -} - -type ChatCustomerResponse struct { - // Types that are valid to be assigned to Resp: - // *ChatCustomerResponse_Session - // *ChatCustomerResponse_Msg - Resp isChatCustomerResponse_Resp `protobuf_oneof:"resp"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ChatCustomerResponse) Reset() { *m = ChatCustomerResponse{} } -func (m *ChatCustomerResponse) String() string { return proto.CompactTextString(m) } -func (*ChatCustomerResponse) ProtoMessage() {} -func (*ChatCustomerResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_bank_a8a0edd183099ef5, []int{14} -} -func (m *ChatCustomerResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ChatCustomerResponse.Unmarshal(m, b) -} -func (m *ChatCustomerResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ChatCustomerResponse.Marshal(b, m, deterministic) -} -func (dst *ChatCustomerResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_ChatCustomerResponse.Merge(dst, src) -} -func (m *ChatCustomerResponse) XXX_Size() int { - return xxx_messageInfo_ChatCustomerResponse.Size(m) -} -func (m *ChatCustomerResponse) XXX_DiscardUnknown() { - xxx_messageInfo_ChatCustomerResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_ChatCustomerResponse proto.InternalMessageInfo - -type isChatCustomerResponse_Resp interface { - isChatCustomerResponse_Resp() -} - -type ChatCustomerResponse_Session struct { - Session *Session `protobuf:"bytes,1,opt,name=session,proto3,oneof"` -} -type ChatCustomerResponse_Msg struct { - Msg *AgentMessage `protobuf:"bytes,2,opt,name=msg,proto3,oneof"` -} - -func (*ChatCustomerResponse_Session) isChatCustomerResponse_Resp() {} -func (*ChatCustomerResponse_Msg) isChatCustomerResponse_Resp() {} - -func (m *ChatCustomerResponse) GetResp() isChatCustomerResponse_Resp { - if m != nil { - return m.Resp - } - return nil -} - -func (m *ChatCustomerResponse) GetSession() *Session { - if x, ok := m.GetResp().(*ChatCustomerResponse_Session); ok { - return x.Session - } - return nil -} - -func (m *ChatCustomerResponse) GetMsg() *AgentMessage { - if x, ok := m.GetResp().(*ChatCustomerResponse_Msg); ok { - return x.Msg - } - return nil -} - -// XXX_OneofFuncs is for the internal use of the proto package. -func (*ChatCustomerResponse) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { - return _ChatCustomerResponse_OneofMarshaler, _ChatCustomerResponse_OneofUnmarshaler, _ChatCustomerResponse_OneofSizer, []interface{}{ - (*ChatCustomerResponse_Session)(nil), - (*ChatCustomerResponse_Msg)(nil), - } -} - -func _ChatCustomerResponse_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { - m := msg.(*ChatCustomerResponse) - // resp - switch x := m.Resp.(type) { - case *ChatCustomerResponse_Session: - b.EncodeVarint(1<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.Session); err != nil { - return err - } - case *ChatCustomerResponse_Msg: - b.EncodeVarint(2<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.Msg); err != nil { - return err - } - case nil: - default: - return fmt.Errorf("ChatCustomerResponse.Resp has unexpected type %T", x) - } - return nil -} - -func _ChatCustomerResponse_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { - m := msg.(*ChatCustomerResponse) - switch tag { - case 1: // resp.session - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(Session) - err := b.DecodeMessage(msg) - m.Resp = &ChatCustomerResponse_Session{msg} - return true, err - case 2: // resp.msg - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(AgentMessage) - err := b.DecodeMessage(msg) - m.Resp = &ChatCustomerResponse_Msg{msg} - return true, err - default: - return false, nil - } -} - -func _ChatCustomerResponse_OneofSizer(msg proto.Message) (n int) { - m := msg.(*ChatCustomerResponse) - // resp - switch x := m.Resp.(type) { - case *ChatCustomerResponse_Session: - s := proto.Size(x.Session) - n += 1 // tag and wire - n += proto.SizeVarint(uint64(s)) - n += s - case *ChatCustomerResponse_Msg: - s := proto.Size(x.Msg) - n += 1 // tag and wire - n += proto.SizeVarint(uint64(s)) - n += s - case nil: - default: - panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) - } - return n -} - -type ChatAgentRequest struct { - // Types that are valid to be assigned to Req: - // *ChatAgentRequest_Accept - // *ChatAgentRequest_Msg - // *ChatAgentRequest_LeaveSession - Req isChatAgentRequest_Req `protobuf_oneof:"req"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ChatAgentRequest) Reset() { *m = ChatAgentRequest{} } -func (m *ChatAgentRequest) String() string { return proto.CompactTextString(m) } -func (*ChatAgentRequest) ProtoMessage() {} -func (*ChatAgentRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_bank_a8a0edd183099ef5, []int{15} -} -func (m *ChatAgentRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ChatAgentRequest.Unmarshal(m, b) -} -func (m *ChatAgentRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ChatAgentRequest.Marshal(b, m, deterministic) -} -func (dst *ChatAgentRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_ChatAgentRequest.Merge(dst, src) -} -func (m *ChatAgentRequest) XXX_Size() int { - return xxx_messageInfo_ChatAgentRequest.Size(m) -} -func (m *ChatAgentRequest) XXX_DiscardUnknown() { - xxx_messageInfo_ChatAgentRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_ChatAgentRequest proto.InternalMessageInfo - -type isChatAgentRequest_Req interface { - isChatAgentRequest_Req() -} - -type ChatAgentRequest_Accept struct { - Accept *AcceptChat `protobuf:"bytes,1,opt,name=accept,proto3,oneof"` -} -type ChatAgentRequest_Msg struct { - Msg string `protobuf:"bytes,2,opt,name=msg,proto3,oneof"` -} -type ChatAgentRequest_LeaveSession struct { - LeaveSession Void `protobuf:"varint,3,opt,name=leave_session,json=leaveSession,proto3,enum=Void,oneof"` -} - -func (*ChatAgentRequest_Accept) isChatAgentRequest_Req() {} -func (*ChatAgentRequest_Msg) isChatAgentRequest_Req() {} -func (*ChatAgentRequest_LeaveSession) isChatAgentRequest_Req() {} - -func (m *ChatAgentRequest) GetReq() isChatAgentRequest_Req { - if m != nil { - return m.Req - } - return nil -} - -func (m *ChatAgentRequest) GetAccept() *AcceptChat { - if x, ok := m.GetReq().(*ChatAgentRequest_Accept); ok { - return x.Accept - } - return nil -} - -func (m *ChatAgentRequest) GetMsg() string { - if x, ok := m.GetReq().(*ChatAgentRequest_Msg); ok { - return x.Msg - } - return "" -} - -func (m *ChatAgentRequest) GetLeaveSession() Void { - if x, ok := m.GetReq().(*ChatAgentRequest_LeaveSession); ok { - return x.LeaveSession - } - return Void_VOID -} - -// XXX_OneofFuncs is for the internal use of the proto package. -func (*ChatAgentRequest) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { - return _ChatAgentRequest_OneofMarshaler, _ChatAgentRequest_OneofUnmarshaler, _ChatAgentRequest_OneofSizer, []interface{}{ - (*ChatAgentRequest_Accept)(nil), - (*ChatAgentRequest_Msg)(nil), - (*ChatAgentRequest_LeaveSession)(nil), - } -} - -func _ChatAgentRequest_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { - m := msg.(*ChatAgentRequest) - // req - switch x := m.Req.(type) { - case *ChatAgentRequest_Accept: - b.EncodeVarint(1<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.Accept); err != nil { - return err - } - case *ChatAgentRequest_Msg: - b.EncodeVarint(2<<3 | proto.WireBytes) - b.EncodeStringBytes(x.Msg) - case *ChatAgentRequest_LeaveSession: - b.EncodeVarint(3<<3 | proto.WireVarint) - b.EncodeVarint(uint64(x.LeaveSession)) - case nil: - default: - return fmt.Errorf("ChatAgentRequest.Req has unexpected type %T", x) - } - return nil -} - -func _ChatAgentRequest_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { - m := msg.(*ChatAgentRequest) - switch tag { - case 1: // req.accept - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(AcceptChat) - err := b.DecodeMessage(msg) - m.Req = &ChatAgentRequest_Accept{msg} - return true, err - case 2: // req.msg - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - x, err := b.DecodeStringBytes() - m.Req = &ChatAgentRequest_Msg{x} - return true, err - case 3: // req.leave_session - if wire != proto.WireVarint { - return true, proto.ErrInternalBadWireType - } - x, err := b.DecodeVarint() - m.Req = &ChatAgentRequest_LeaveSession{Void(x)} - return true, err - default: - return false, nil - } -} - -func _ChatAgentRequest_OneofSizer(msg proto.Message) (n int) { - m := msg.(*ChatAgentRequest) - // req - switch x := m.Req.(type) { - case *ChatAgentRequest_Accept: - s := proto.Size(x.Accept) - n += 1 // tag and wire - n += proto.SizeVarint(uint64(s)) - n += s - case *ChatAgentRequest_Msg: - n += 1 // tag and wire - n += proto.SizeVarint(uint64(len(x.Msg))) - n += len(x.Msg) - case *ChatAgentRequest_LeaveSession: - n += 1 // tag and wire - n += proto.SizeVarint(uint64(x.LeaveSession)) - case nil: - default: - panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) - } - return n -} - -type AcceptChat struct { - SessionId string `protobuf:"bytes,1,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *AcceptChat) Reset() { *m = AcceptChat{} } -func (m *AcceptChat) String() string { return proto.CompactTextString(m) } -func (*AcceptChat) ProtoMessage() {} -func (*AcceptChat) Descriptor() ([]byte, []int) { - return fileDescriptor_bank_a8a0edd183099ef5, []int{16} -} -func (m *AcceptChat) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_AcceptChat.Unmarshal(m, b) -} -func (m *AcceptChat) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_AcceptChat.Marshal(b, m, deterministic) -} -func (dst *AcceptChat) XXX_Merge(src proto.Message) { - xxx_messageInfo_AcceptChat.Merge(dst, src) -} -func (m *AcceptChat) XXX_Size() int { - return xxx_messageInfo_AcceptChat.Size(m) -} -func (m *AcceptChat) XXX_DiscardUnknown() { - xxx_messageInfo_AcceptChat.DiscardUnknown(m) -} - -var xxx_messageInfo_AcceptChat proto.InternalMessageInfo - -func (m *AcceptChat) GetSessionId() string { - if m != nil { - return m.SessionId - } - return "" -} - -type ChatEntry struct { - Date *timestamp.Timestamp `protobuf:"bytes,1,opt,name=date,proto3" json:"date,omitempty"` - // Types that are valid to be assigned to Entry: - // *ChatEntry_CustomerMsg - // *ChatEntry_AgentMsg - Entry isChatEntry_Entry `protobuf_oneof:"entry"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ChatEntry) Reset() { *m = ChatEntry{} } -func (m *ChatEntry) String() string { return proto.CompactTextString(m) } -func (*ChatEntry) ProtoMessage() {} -func (*ChatEntry) Descriptor() ([]byte, []int) { - return fileDescriptor_bank_a8a0edd183099ef5, []int{17} -} -func (m *ChatEntry) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ChatEntry.Unmarshal(m, b) -} -func (m *ChatEntry) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ChatEntry.Marshal(b, m, deterministic) -} -func (dst *ChatEntry) XXX_Merge(src proto.Message) { - xxx_messageInfo_ChatEntry.Merge(dst, src) -} -func (m *ChatEntry) XXX_Size() int { - return xxx_messageInfo_ChatEntry.Size(m) -} -func (m *ChatEntry) XXX_DiscardUnknown() { - xxx_messageInfo_ChatEntry.DiscardUnknown(m) -} - -var xxx_messageInfo_ChatEntry proto.InternalMessageInfo - -type isChatEntry_Entry interface { - isChatEntry_Entry() -} - -type ChatEntry_CustomerMsg struct { - CustomerMsg string `protobuf:"bytes,2,opt,name=customer_msg,json=customerMsg,proto3,oneof"` -} -type ChatEntry_AgentMsg struct { - AgentMsg *AgentMessage `protobuf:"bytes,3,opt,name=agent_msg,json=agentMsg,proto3,oneof"` -} - -func (*ChatEntry_CustomerMsg) isChatEntry_Entry() {} -func (*ChatEntry_AgentMsg) isChatEntry_Entry() {} - -func (m *ChatEntry) GetEntry() isChatEntry_Entry { - if m != nil { - return m.Entry - } - return nil -} - -func (m *ChatEntry) GetDate() *timestamp.Timestamp { - if m != nil { - return m.Date - } - return nil -} - -func (m *ChatEntry) GetCustomerMsg() string { - if x, ok := m.GetEntry().(*ChatEntry_CustomerMsg); ok { - return x.CustomerMsg - } - return "" -} - -func (m *ChatEntry) GetAgentMsg() *AgentMessage { - if x, ok := m.GetEntry().(*ChatEntry_AgentMsg); ok { - return x.AgentMsg - } - return nil -} - -// XXX_OneofFuncs is for the internal use of the proto package. -func (*ChatEntry) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { - return _ChatEntry_OneofMarshaler, _ChatEntry_OneofUnmarshaler, _ChatEntry_OneofSizer, []interface{}{ - (*ChatEntry_CustomerMsg)(nil), - (*ChatEntry_AgentMsg)(nil), - } -} - -func _ChatEntry_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { - m := msg.(*ChatEntry) - // entry - switch x := m.Entry.(type) { - case *ChatEntry_CustomerMsg: - b.EncodeVarint(2<<3 | proto.WireBytes) - b.EncodeStringBytes(x.CustomerMsg) - case *ChatEntry_AgentMsg: - b.EncodeVarint(3<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.AgentMsg); err != nil { - return err - } - case nil: - default: - return fmt.Errorf("ChatEntry.Entry has unexpected type %T", x) - } - return nil -} - -func _ChatEntry_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { - m := msg.(*ChatEntry) - switch tag { - case 2: // entry.customer_msg - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - x, err := b.DecodeStringBytes() - m.Entry = &ChatEntry_CustomerMsg{x} - return true, err - case 3: // entry.agent_msg - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(AgentMessage) - err := b.DecodeMessage(msg) - m.Entry = &ChatEntry_AgentMsg{msg} - return true, err - default: - return false, nil - } -} - -func _ChatEntry_OneofSizer(msg proto.Message) (n int) { - m := msg.(*ChatEntry) - // entry - switch x := m.Entry.(type) { - case *ChatEntry_CustomerMsg: - n += 1 // tag and wire - n += proto.SizeVarint(uint64(len(x.CustomerMsg))) - n += len(x.CustomerMsg) - case *ChatEntry_AgentMsg: - s := proto.Size(x.AgentMsg) - n += 1 // tag and wire - n += proto.SizeVarint(uint64(s)) - n += s - case nil: - default: - panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) - } - return n -} - -type ChatAgentResponse struct { - // Types that are valid to be assigned to Resp: - // *ChatAgentResponse_AcceptedSession - // *ChatAgentResponse_Msg - // *ChatAgentResponse_SessionEnded - Resp isChatAgentResponse_Resp `protobuf_oneof:"resp"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ChatAgentResponse) Reset() { *m = ChatAgentResponse{} } -func (m *ChatAgentResponse) String() string { return proto.CompactTextString(m) } -func (*ChatAgentResponse) ProtoMessage() {} -func (*ChatAgentResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_bank_a8a0edd183099ef5, []int{18} -} -func (m *ChatAgentResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ChatAgentResponse.Unmarshal(m, b) -} -func (m *ChatAgentResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ChatAgentResponse.Marshal(b, m, deterministic) -} -func (dst *ChatAgentResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_ChatAgentResponse.Merge(dst, src) -} -func (m *ChatAgentResponse) XXX_Size() int { - return xxx_messageInfo_ChatAgentResponse.Size(m) -} -func (m *ChatAgentResponse) XXX_DiscardUnknown() { - xxx_messageInfo_ChatAgentResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_ChatAgentResponse proto.InternalMessageInfo - -type isChatAgentResponse_Resp interface { - isChatAgentResponse_Resp() -} - -type ChatAgentResponse_AcceptedSession struct { - AcceptedSession *Session `protobuf:"bytes,1,opt,name=accepted_session,json=acceptedSession,proto3,oneof"` -} -type ChatAgentResponse_Msg struct { - Msg *ChatEntry `protobuf:"bytes,2,opt,name=msg,proto3,oneof"` -} -type ChatAgentResponse_SessionEnded struct { - SessionEnded Void `protobuf:"varint,3,opt,name=session_ended,json=sessionEnded,proto3,enum=Void,oneof"` -} - -func (*ChatAgentResponse_AcceptedSession) isChatAgentResponse_Resp() {} -func (*ChatAgentResponse_Msg) isChatAgentResponse_Resp() {} -func (*ChatAgentResponse_SessionEnded) isChatAgentResponse_Resp() {} - -func (m *ChatAgentResponse) GetResp() isChatAgentResponse_Resp { - if m != nil { - return m.Resp - } - return nil -} - -func (m *ChatAgentResponse) GetAcceptedSession() *Session { - if x, ok := m.GetResp().(*ChatAgentResponse_AcceptedSession); ok { - return x.AcceptedSession - } - return nil -} - -func (m *ChatAgentResponse) GetMsg() *ChatEntry { - if x, ok := m.GetResp().(*ChatAgentResponse_Msg); ok { - return x.Msg - } - return nil -} - -func (m *ChatAgentResponse) GetSessionEnded() Void { - if x, ok := m.GetResp().(*ChatAgentResponse_SessionEnded); ok { - return x.SessionEnded - } - return Void_VOID -} - -// XXX_OneofFuncs is for the internal use of the proto package. -func (*ChatAgentResponse) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { - return _ChatAgentResponse_OneofMarshaler, _ChatAgentResponse_OneofUnmarshaler, _ChatAgentResponse_OneofSizer, []interface{}{ - (*ChatAgentResponse_AcceptedSession)(nil), - (*ChatAgentResponse_Msg)(nil), - (*ChatAgentResponse_SessionEnded)(nil), - } -} - -func _ChatAgentResponse_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { - m := msg.(*ChatAgentResponse) - // resp - switch x := m.Resp.(type) { - case *ChatAgentResponse_AcceptedSession: - b.EncodeVarint(1<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.AcceptedSession); err != nil { - return err - } - case *ChatAgentResponse_Msg: - b.EncodeVarint(2<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.Msg); err != nil { - return err - } - case *ChatAgentResponse_SessionEnded: - b.EncodeVarint(3<<3 | proto.WireVarint) - b.EncodeVarint(uint64(x.SessionEnded)) - case nil: - default: - return fmt.Errorf("ChatAgentResponse.Resp has unexpected type %T", x) - } - return nil -} - -func _ChatAgentResponse_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { - m := msg.(*ChatAgentResponse) - switch tag { - case 1: // resp.accepted_session - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(Session) - err := b.DecodeMessage(msg) - m.Resp = &ChatAgentResponse_AcceptedSession{msg} - return true, err - case 2: // resp.msg - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(ChatEntry) - err := b.DecodeMessage(msg) - m.Resp = &ChatAgentResponse_Msg{msg} - return true, err - case 3: // resp.session_ended - if wire != proto.WireVarint { - return true, proto.ErrInternalBadWireType - } - x, err := b.DecodeVarint() - m.Resp = &ChatAgentResponse_SessionEnded{Void(x)} - return true, err - default: - return false, nil - } -} - -func _ChatAgentResponse_OneofSizer(msg proto.Message) (n int) { - m := msg.(*ChatAgentResponse) - // resp - switch x := m.Resp.(type) { - case *ChatAgentResponse_AcceptedSession: - s := proto.Size(x.AcceptedSession) - n += 1 // tag and wire - n += proto.SizeVarint(uint64(s)) - n += s - case *ChatAgentResponse_Msg: - s := proto.Size(x.Msg) - n += 1 // tag and wire - n += proto.SizeVarint(uint64(s)) - n += s - case *ChatAgentResponse_SessionEnded: - n += 1 // tag and wire - n += proto.SizeVarint(uint64(x.SessionEnded)) - case nil: - default: - panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) - } - return n -} - -type Session struct { - SessionId string `protobuf:"bytes,1,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"` - CustomerName string `protobuf:"bytes,2,opt,name=customer_name,json=customerName,proto3" json:"customer_name,omitempty"` - History []*ChatEntry `protobuf:"bytes,3,rep,name=history,proto3" json:"history,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Session) Reset() { *m = Session{} } -func (m *Session) String() string { return proto.CompactTextString(m) } -func (*Session) ProtoMessage() {} -func (*Session) Descriptor() ([]byte, []int) { - return fileDescriptor_bank_a8a0edd183099ef5, []int{19} -} -func (m *Session) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Session.Unmarshal(m, b) -} -func (m *Session) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Session.Marshal(b, m, deterministic) -} -func (dst *Session) XXX_Merge(src proto.Message) { - xxx_messageInfo_Session.Merge(dst, src) -} -func (m *Session) XXX_Size() int { - return xxx_messageInfo_Session.Size(m) -} -func (m *Session) XXX_DiscardUnknown() { - xxx_messageInfo_Session.DiscardUnknown(m) -} - -var xxx_messageInfo_Session proto.InternalMessageInfo - -func (m *Session) GetSessionId() string { - if m != nil { - return m.SessionId - } - return "" -} - -func (m *Session) GetCustomerName() string { - if m != nil { - return m.CustomerName - } - return "" -} - -func (m *Session) GetHistory() []*ChatEntry { - if m != nil { - return m.History - } - return nil -} - func init() { proto.RegisterType((*OpenAccountRequest)(nil), "OpenAccountRequest") proto.RegisterType((*CloseAccountRequest)(nil), "CloseAccountRequest") @@ -1897,16 +912,6 @@ func init() { proto.RegisterType((*TransferRequest)(nil), "TransferRequest") proto.RegisterType((*TransferRequest_ExternalAccount)(nil), "TransferRequest.ExternalAccount") proto.RegisterType((*TransferResponse)(nil), "TransferResponse") - proto.RegisterType((*ChatCustomerRequest)(nil), "ChatCustomerRequest") - proto.RegisterType((*InitiateChat)(nil), "InitiateChat") - proto.RegisterType((*AgentMessage)(nil), "AgentMessage") - proto.RegisterType((*ChatCustomerResponse)(nil), "ChatCustomerResponse") - proto.RegisterType((*ChatAgentRequest)(nil), "ChatAgentRequest") - proto.RegisterType((*AcceptChat)(nil), "AcceptChat") - proto.RegisterType((*ChatEntry)(nil), "ChatEntry") - proto.RegisterType((*ChatAgentResponse)(nil), "ChatAgentResponse") - proto.RegisterType((*Session)(nil), "Session") - proto.RegisterEnum("Void", Void_name, Void_value) proto.RegisterEnum("Account_Type", Account_Type_name, Account_Type_value) proto.RegisterEnum("DepositRequest_Source", DepositRequest_Source_name, DepositRequest_Source_value) } @@ -2237,269 +1242,66 @@ var _Bank_serviceDesc = grpc.ServiceDesc{ Metadata: "bank.proto", } -// SupportClient is the client API for Support service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type SupportClient interface { - // ChatCustomer is used by a customer-facing app to send the customer's messages - // to a chat session. The customer is how initiates and terminates (via "hangup") - // a chat session. Only customers may invoke this method (e.g. requests must - // include customer auth credentials). - ChatCustomer(ctx context.Context, opts ...grpc.CallOption) (Support_ChatCustomerClient, error) - // ChatAgent is used by an agent-facing app to allow an agent to reply to a - // customer's messages in a chat session. The agent may accept a chat session, - // which defaults to the session awaiting an agent for the longest period of time - // (FIFO queue). - ChatAgent(ctx context.Context, opts ...grpc.CallOption) (Support_ChatAgentClient, error) -} +func init() { proto.RegisterFile("bank.proto", fileDescriptor_bank_485eb966c3eae5d1) } -type supportClient struct { - cc *grpc.ClientConn -} - -func NewSupportClient(cc *grpc.ClientConn) SupportClient { - return &supportClient{cc} -} - -func (c *supportClient) ChatCustomer(ctx context.Context, opts ...grpc.CallOption) (Support_ChatCustomerClient, error) { - stream, err := c.cc.NewStream(ctx, &_Support_serviceDesc.Streams[0], "/Support/ChatCustomer", opts...) - if err != nil { - return nil, err - } - x := &supportChatCustomerClient{stream} - return x, nil -} - -type Support_ChatCustomerClient interface { - Send(*ChatCustomerRequest) error - Recv() (*ChatCustomerResponse, error) - grpc.ClientStream -} - -type supportChatCustomerClient struct { - grpc.ClientStream -} - -func (x *supportChatCustomerClient) Send(m *ChatCustomerRequest) error { - return x.ClientStream.SendMsg(m) -} - -func (x *supportChatCustomerClient) Recv() (*ChatCustomerResponse, error) { - m := new(ChatCustomerResponse) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func (c *supportClient) ChatAgent(ctx context.Context, opts ...grpc.CallOption) (Support_ChatAgentClient, error) { - stream, err := c.cc.NewStream(ctx, &_Support_serviceDesc.Streams[1], "/Support/ChatAgent", opts...) - if err != nil { - return nil, err - } - x := &supportChatAgentClient{stream} - return x, nil -} - -type Support_ChatAgentClient interface { - Send(*ChatAgentRequest) error - Recv() (*ChatAgentResponse, error) - grpc.ClientStream -} - -type supportChatAgentClient struct { - grpc.ClientStream -} - -func (x *supportChatAgentClient) Send(m *ChatAgentRequest) error { - return x.ClientStream.SendMsg(m) -} - -func (x *supportChatAgentClient) Recv() (*ChatAgentResponse, error) { - m := new(ChatAgentResponse) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -// SupportServer is the server API for Support service. -type SupportServer interface { - // ChatCustomer is used by a customer-facing app to send the customer's messages - // to a chat session. The customer is how initiates and terminates (via "hangup") - // a chat session. Only customers may invoke this method (e.g. requests must - // include customer auth credentials). - ChatCustomer(Support_ChatCustomerServer) error - // ChatAgent is used by an agent-facing app to allow an agent to reply to a - // customer's messages in a chat session. The agent may accept a chat session, - // which defaults to the session awaiting an agent for the longest period of time - // (FIFO queue). - ChatAgent(Support_ChatAgentServer) error -} - -func RegisterSupportServer(s *grpc.Server, srv SupportServer) { - s.RegisterService(&_Support_serviceDesc, srv) -} - -func _Support_ChatCustomer_Handler(srv interface{}, stream grpc.ServerStream) error { - return srv.(SupportServer).ChatCustomer(&supportChatCustomerServer{stream}) -} - -type Support_ChatCustomerServer interface { - Send(*ChatCustomerResponse) error - Recv() (*ChatCustomerRequest, error) - grpc.ServerStream -} - -type supportChatCustomerServer struct { - grpc.ServerStream -} - -func (x *supportChatCustomerServer) Send(m *ChatCustomerResponse) error { - return x.ServerStream.SendMsg(m) -} - -func (x *supportChatCustomerServer) Recv() (*ChatCustomerRequest, error) { - m := new(ChatCustomerRequest) - if err := x.ServerStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func _Support_ChatAgent_Handler(srv interface{}, stream grpc.ServerStream) error { - return srv.(SupportServer).ChatAgent(&supportChatAgentServer{stream}) -} - -type Support_ChatAgentServer interface { - Send(*ChatAgentResponse) error - Recv() (*ChatAgentRequest, error) - grpc.ServerStream -} - -type supportChatAgentServer struct { - grpc.ServerStream -} - -func (x *supportChatAgentServer) Send(m *ChatAgentResponse) error { - return x.ServerStream.SendMsg(m) -} - -func (x *supportChatAgentServer) Recv() (*ChatAgentRequest, error) { - m := new(ChatAgentRequest) - if err := x.ServerStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -var _Support_serviceDesc = grpc.ServiceDesc{ - ServiceName: "Support", - HandlerType: (*SupportServer)(nil), - Methods: []grpc.MethodDesc{}, - Streams: []grpc.StreamDesc{ - { - StreamName: "ChatCustomer", - Handler: _Support_ChatCustomer_Handler, - ServerStreams: true, - ClientStreams: true, - }, - { - StreamName: "ChatAgent", - Handler: _Support_ChatAgent_Handler, - ServerStreams: true, - ClientStreams: true, - }, - }, - Metadata: "bank.proto", -} - -func init() { proto.RegisterFile("bank.proto", fileDescriptor_bank_a8a0edd183099ef5) } - -var fileDescriptor_bank_a8a0edd183099ef5 = []byte{ - // 1336 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x56, 0xcd, 0x6e, 0xdb, 0x46, - 0x10, 0x16, 0x25, 0xea, 0x6f, 0x24, 0x5b, 0xf4, 0x2a, 0x49, 0x0d, 0x15, 0x6d, 0x1d, 0x26, 0x05, - 0x8c, 0x54, 0xd8, 0x18, 0xea, 0xcf, 0x21, 0x49, 0x11, 0x48, 0xb2, 0x6a, 0x09, 0x8e, 0x65, 0x94, - 0x76, 0x12, 0xb4, 0x40, 0x41, 0xac, 0xa9, 0x8d, 0x4c, 0xd8, 0x22, 0x69, 0xee, 0xaa, 0xa9, 0xaf, - 0x79, 0x89, 0x1e, 0xdb, 0xe7, 0xe8, 0x0b, 0x14, 0xe8, 0x3b, 0xf4, 0xd8, 0x97, 0xe8, 0xa9, 0xd8, - 0xe5, 0x92, 0xa6, 0x28, 0xc5, 0x50, 0x80, 0xde, 0xa4, 0xf9, 0x3e, 0xee, 0xcc, 0x7c, 0x33, 0xbb, - 0x33, 0x00, 0x67, 0xc4, 0xbb, 0xc0, 0x41, 0xe8, 0x73, 0xbf, 0xf5, 0xf1, 0xd4, 0xf7, 0xa7, 0x97, - 0xf4, 0xb1, 0xfc, 0x77, 0x36, 0x7f, 0xf3, 0x98, 0xce, 0x02, 0x7e, 0xad, 0xc0, 0xcf, 0xb2, 0x20, - 0x77, 0x67, 0x94, 0x71, 0x32, 0x0b, 0x22, 0x82, 0x79, 0x01, 0xe8, 0x38, 0xa0, 0x5e, 0xd7, 0x71, - 0xfc, 0xb9, 0xc7, 0x2d, 0x7a, 0x35, 0xa7, 0x8c, 0xa3, 0x0e, 0xdc, 0x75, 0x3d, 0x97, 0xbb, 0xe4, - 0xd2, 0x9e, 0xd0, 0xc0, 0x67, 0x2e, 0xb7, 0x1d, 0xea, 0x71, 0xb6, 0xad, 0xed, 0x68, 0xbb, 0x45, - 0xab, 0xa9, 0xc0, 0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x02, 0xfa, 0x8b, 0xe3, 0xee, 0xd8, 0x28, 0x8a, - 0x93, 0x06, 0xdf, 0xbf, 0x1c, 0x9d, 0x8e, 0x06, 0x27, 0x46, 0xc9, 0xfc, 0x4d, 0x83, 0x7b, 0x07, - 0x94, 0x9f, 0x86, 0xc4, 0x63, 0xc4, 0xe1, 0xae, 0xef, 0xb1, 0x0f, 0x93, 0x19, 0xed, 0x41, 0x91, - 0x71, 0x12, 0x72, 0x99, 0x77, 0xad, 0xd3, 0xc2, 0x51, 0x0b, 0xe1, 0xb8, 0x85, 0xf0, 0x69, 0xdc, - 0x42, 0x56, 0x44, 0x44, 0x6d, 0x28, 0x50, 0x6f, 0x22, 0x73, 0xbf, 0x9d, 0x2f, 0x68, 0xe6, 0x1f, - 0x1a, 0xd4, 0x52, 0xe1, 0xad, 0x1b, 0xd6, 0x27, 0x00, 0x8c, 0x5e, 0xc5, 0x94, 0xbc, 0xa4, 0x54, - 0x19, 0xbd, 0x52, 0x30, 0x06, 0x7d, 0x42, 0x38, 0x5d, 0x23, 0x08, 0xc9, 0x43, 0xf7, 0xa1, 0x4e, - 0x66, 0xd2, 0x69, 0x54, 0x38, 0x5d, 0x16, 0xae, 0x16, 0xd9, 0xa2, 0x86, 0x46, 0xa0, 0x4f, 0x28, - 0x73, 0xb6, 0x8b, 0x3b, 0xda, 0x6e, 0xd5, 0x92, 0xbf, 0xcd, 0xbf, 0x35, 0xd8, 0x54, 0x5d, 0xff, - 0x81, 0xb2, 0x66, 0x1d, 0xe6, 0x97, 0x1d, 0x62, 0x28, 0x31, 0x7f, 0x1e, 0x3a, 0x51, 0x16, 0x9b, - 0x9d, 0x7b, 0x78, 0xd1, 0x15, 0x3e, 0x91, 0xa8, 0xa5, 0x58, 0x49, 0x80, 0x7a, 0x2a, 0xc0, 0x6f, - 0xa1, 0x14, 0xb1, 0x16, 0xdb, 0xad, 0x02, 0x7a, 0xbf, 0x7b, 0x32, 0x34, 0x34, 0x54, 0x85, 0xa2, - 0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 0x9e, 0x7e, 0x67, 0x84, - 0xa2, 0xcb, 0x8f, 0x6d, 0xeb, 0x2e, 0x5e, 0xf5, 0x18, 0xed, 0x6a, 0x7b, 0x1a, 0xfa, 0x26, 0xba, - 0x8c, 0xb2, 0xe5, 0xd1, 0x16, 0xce, 0x3e, 0x25, 0x2d, 0x84, 0x97, 0x6e, 0x84, 0xf8, 0xae, 0x57, - 0xfa, 0x51, 0x9f, 0x11, 0xd7, 0x3b, 0x2b, 0x49, 0xf5, 0xbf, 0xfc, 0x2f, 0x00, 0x00, 0xff, 0xff, - 0x4f, 0x31, 0xdc, 0x9e, 0xa7, 0x0d, 0x00, 0x00, +var fileDescriptor_bank_485eb966c3eae5d1 = []byte{ + // 913 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x56, 0xdd, 0x6e, 0xe2, 0x46, + 0x18, 0x8d, 0xb1, 0x21, 0xe4, 0x83, 0xc0, 0x64, 0xd8, 0x4d, 0x23, 0x57, 0x55, 0xb3, 0x6e, 0x2b, + 0x45, 0x15, 0x9a, 0x44, 0xb4, 0x57, 0xdd, 0xed, 0x05, 0x10, 0x37, 0xa0, 0xec, 0x82, 0x3a, 0x61, + 0x1b, 0xb5, 0x52, 0x65, 0x19, 0x33, 0x9b, 0x58, 0x01, 0x9b, 0x78, 0x06, 0xb5, 0x79, 0x9a, 0xbe, + 0x47, 0x5f, 0xa0, 0x52, 0xdf, 0xa1, 0x97, 0x7d, 0x89, 0x5e, 0x55, 0x1e, 0x8f, 0x59, 0xe3, 0x78, + 0x57, 0xac, 0xb4, 0x77, 0x66, 0xce, 0x99, 0x39, 0xdf, 0xcf, 0x99, 0xf9, 0x00, 0x98, 0xba, 0xc1, + 0x1d, 0x59, 0x46, 0xa1, 0x08, 0xcd, 0x4f, 0x6f, 0xc2, 0xf0, 0x66, 0xce, 0x4e, 0xe5, 0xaf, 0xe9, + 0xea, 0xcd,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 0x68, 0xcc, 0x3a, 0xc9, 0xac, 0x9e, + 0x69, 0xb8, 0x0d, 0xbb, 0xea, 0x21, 0xc3, 0xcd, 0xdc, 0x93, 0x66, 0x22, 0x92, 0x7f, 0x6f, 0x08, + 0x54, 0xd3, 0x37, 0x02, 0x23, 0x92, 0x7b, 0x2e, 0x0a, 0xf8, 0xa7, 0x50, 0x4d, 0x7d, 0x81, 0x51, + 0xfe, 0x3a, 0x98, 0x07, 0x24, 0x6f, 0x9a, 0x5e, 0xe5, 0x17, 0x63, 0xe1, 0xfa, 0xc1, 0xb4, 0x22, + 0x13, 0xff, 0xe6, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xac, 0x47, 0x1e, 0xdd, 0x4d, 0x09, 0x00, + 0x00, } diff --git a/testing/cmd/bankdemo/bank.proto b/testing/cmd/bankdemo/bank.proto index c2e5ab7..8c7b4b9 100644 --- a/testing/cmd/bankdemo/bank.proto +++ b/testing/cmd/bankdemo/bank.proto @@ -33,24 +33,6 @@ service Bank { rpc Transfer(TransferRequest) returns (TransferResponse); } -// Support provides an interactive chat service, for customers to interact with -// the bank's support agents. A single stream, for either of the two methods, is -// a stateful connection to a single "chat session". Streams are initially disconnected -// (not part of any session). A stream must be disconnected from a session (via customer -// hang up or via agent leaving a session) before it can be connected to a new one. -service Support { - // ChatCustomer is used by a customer-facing app to send the customer's messages - // to a chat session. The customer is how initiates and terminates (via "hangup") - // a chat session. Only customers may invoke this method (e.g. requests must - // include customer auth credentials). - rpc ChatCustomer(stream ChatCustomerRequest) returns (stream ChatCustomerResponse); - // ChatAgent is used by an agent-facing app to allow an agent to reply to a - // customer's messages in a chat session. The agent may accept a chat session, - // which defaults to the session awaiting an agent for the longest period of time - // (FIFO queue). - rpc ChatAgent(stream ChatAgentRequest) returns (stream ChatAgentResponse); -} - message OpenAccountRequest { int32 initial_deposit_cents = 1; Account.Type type = 2; @@ -141,98 +123,3 @@ message TransferResponse { uint64 dest_account_number = 3; int32 dest_balance_cents = 4; } - -enum Void { - VOID = 0; -} - -message ChatCustomerRequest { - oneof req { - // init is used when a chat stream is not part of a - // chat session. This is a stream's initial state, as well as - // the state after a "hang_up" request is sent. This creates - // a new state session or resumes an existing one. - InitiateChat init = 1; - // msg is used to send the customer's messages to support - // agents. - string msg = 2; - // hang_up is used to terminate a chat session. If a stream - // is broken, but the session was not terminated, the client - // may initiate a new stream and use init to resume that - // session. Sessions are not terminated unless done so - // explicitly via sending this kind of request on the stream. - Void hang_up = 3; - } -} - -message InitiateChat { - string resume_session_id = 1; -} - -message AgentMessage { - string agent_name = 1; - string msg = 2; -} - -message ChatCustomerResponse { - oneof resp { - // session is sent from the server when the stream is connected - // to a chat session. This happens after an init request is sent - // and the stream is connected to either a new or resumed session. - Session session = 1; - // msg is sent from the server to convey agents' messages to the - // customer. - AgentMessage msg = 2; - } -} - -message ChatAgentRequest { - oneof req { - // accept is used when an agent wants to join a customer chat - // session. It can be used to connect to a specific session (by - // ID), or to just accept the session for which the customer has - // been waiting the longest (e.g. poll a FIFO queue of sessions - // awaiting a support agent). It is possible for multiple agents - // to be connected to the same chat session. - AcceptChat accept = 1; - // msg is used to send a message to the customer. It will also be - // delivered to any other connected support agents. - string msg = 2; - // leave_session allows an agent to exit a chat session. They can - // always re-enter later by sending an accept message for that - // session ID. - Void leave_session = 3; - } -} - -message AcceptChat { - string session_id = 1; -} - -message ChatEntry { - google.protobuf.Timestamp date = 1; - oneof entry { - string customer_msg = 2; - AgentMessage agent_msg = 3; - } -} - -message ChatAgentResponse { - oneof resp { - // accepted_session provides the detail of a chat session. The server - // sends this message after the agent has accepted a chat session. - Session accepted_session = 1; - // msg is sent by the server when the customer, or another support - // agent, sends a message in stream's current session. - ChatEntry msg = 2; - // session_ended notifies the support agent that their currently - // connected chat session has been terminated by the customer. - Void session_ended = 3; - } -} - -message Session { - string session_id = 1; - string customer_name = 2; - repeated ChatEntry history = 3; -} \ No newline at end of file diff --git a/testing/cmd/bankdemo/db.go b/testing/cmd/bankdemo/db.go index bf05b3f..cae2b53 100644 --- a/testing/cmd/bankdemo/db.go +++ b/testing/cmd/bankdemo/db.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "fmt" "sync" "github.com/golang/protobuf/jsonpb" @@ -21,20 +22,111 @@ type accounts struct { mu sync.RWMutex } +func (a *accounts) openAccount(customer string, accountType Account_Type, initialBalanceCents int32) *Account { + a.mu.Lock() + defer a.mu.Unlock() + + accountNums, ok := a.AccountNumbersByCustomer[customer] + if !ok { + // no accounts for this customer? it's a new customer + a.Customers = append(a.Customers, customer) + } + num := a.LastAccountNum + 1 + a.LastAccountNum = num + a.AccountNumbers = append(a.AccountNumbers, num) + accountNums = append(accountNums, num) + a.AccountNumbersByCustomer[customer] = accountNums + var acct account + acct.AccountNumber = num + acct.BalanceCents = initialBalanceCents + acct.Transactions = append(acct.Transactions, &Transaction{ + AccountNumber: num, + SeqNumber: 1, + Date: ptypes.TimestampNow(), + AmountCents: initialBalanceCents, + Desc: "initial deposit", + }) + a.AccountsByNumber[num] = &acct + return &acct.Account +} + +func (a *accounts) closeAccount(customer string, accountNumber uint64) error { + a.mu.Lock() + defer a.mu.Unlock() + + acctNums := a.AccountNumbersByCustomer[customer] + found := -1 + for i, num := range acctNums { + if num == accountNumber { + found = i + break + } + } + if found == -1 { + return status.Errorf(codes.NotFound, "you have no account numbered %d", accountNumber) + } + + acct := a.AccountsByNumber[accountNumber] + if acct.BalanceCents != 0 { + return status.Errorf(codes.FailedPrecondition, "account %d cannot be closed because it has a non-zero balance: %s", accountNumber, dollars(acct.BalanceCents)) + } + + for i, num := range a.AccountNumbers { + if num == accountNumber { + a.AccountNumbers = append(a.AccountNumbers[:i], a.AccountNumbers[i+1:]...) + break + } + } + + a.AccountNumbersByCustomer[customer] = append(acctNums[:found], acctNums[found+1:]...) + delete(a.AccountsByNumber, accountNumber) + return nil +} + +func (a *accounts) getAccount(customer string, accountNumber uint64) (*account, error) { + a.mu.RLock() + defer a.mu.RUnlock() + acctNums := a.AccountNumbersByCustomer[customer] + for _, num := range acctNums { + if num == accountNumber { + return a.AccountsByNumber[num], nil + } + } + return nil, status.Errorf(codes.NotFound, "you have no account numbered %d", accountNumber) +} + +func (a *accounts) getAllAccounts(customer string) []*Account { + a.mu.RLock() + defer a.mu.RUnlock() + + accountNums := a.AccountNumbersByCustomer[customer] + var accounts []*Account + for _, num := range accountNums { + accounts = append(accounts, &a.AccountsByNumber[num].Account) + } + return accounts +} + type account struct { Account Transactions []*Transaction mu sync.RWMutex } -func (a *account) newTransaction(amountCents int32, desc string) (int32, error) { +func (a *account) getTransactions() []*Transaction { + a.mu.RLock() + defer a.mu.RUnlock() + return a.Transactions +} + +func (a *account) newTransaction(amountCents int32, desc string) (newBalance int32, err error) { a.mu.Lock() defer a.mu.Unlock() - newBalance := a.BalanceCents + amountCents - if newBalance < 0 { + bal := a.BalanceCents + amountCents + if bal < 0 { return 0, status.Errorf(codes.FailedPrecondition, "insufficient funds: cannot withdraw %s when balance is %s", dollars(amountCents), dollars(a.BalanceCents)) } - a.BalanceCents += amountCents + a.BalanceCents = bal a.Transactions = append(a.Transactions, &Transaction{ AccountNumber: a.AccountNumber, Date: ptypes.TimestampNow(), @@ -42,7 +134,7 @@ func (a *account) newTransaction(amountCents int32, desc string) (int32, error) SeqNumber: uint64(len(a.Transactions) + 1), Desc: desc, }) - return a.BalanceCents, nil + return bal, nil } func (t *Transaction) MarshalJSON() ([]byte, error) { @@ -58,7 +150,7 @@ func (t *Transaction) UnmarshalJSON(b []byte) error { return jsonpb.Unmarshal(bytes.NewReader(b), t) } -func (a *accounts) Clone() *accounts { +func (a *accounts) clone() *accounts { var clone accounts clone.AccountNumbersByCustomer = map[string][]uint64{} clone.AccountsByNumber = map[uint64]*account{} @@ -91,3 +183,7 @@ func (a *accounts) Clone() *accounts { return &clone } + +func dollars(amountCents int32) string { + return fmt.Sprintf("$%02f", float64(amountCents)/100) +} diff --git a/testing/cmd/bankdemo/main.go b/testing/cmd/bankdemo/main.go index aba3940..77b5cf4 100644 --- a/testing/cmd/bankdemo/main.go +++ b/testing/cmd/bankdemo/main.go @@ -1,6 +1,6 @@ package main -//go:generate protoc --go_out=plugins=grpc:./ bank.proto +//go:generate protoc --go_out=plugins=grpc:./ bank.proto support.proto import ( "encoding/json" @@ -9,8 +9,9 @@ import ( "io/ioutil" "net" "os" - "sync" + "os/signal" "sync/atomic" + "syscall" "time" "golang.org/x/net/context" @@ -67,6 +68,16 @@ func main() { s.flush() }() + // trap SIGINT / SIGTERM to exit cleanly + c := make(chan os.Signal, 1) + signal.Notify(c, syscall.SIGINT) + signal.Notify(c, syscall.SIGTERM) + go func() { + <-c + fmt.Println("Shutting down...") + grpcSvr.GracefulStop() + }() + grpclog.Infof("server starting, listening on %v", l.Addr()) if err := grpcSvr.Serve(l); err != nil { panic(err) @@ -112,11 +123,9 @@ func gRPCServer() *grpc.Server { } type svr struct { - datafile string - ctx context.Context - cancel context.CancelFunc - - mu sync.Mutex + datafile string + ctx context.Context + cancel context.CancelFunc allAccounts accounts } @@ -149,10 +158,9 @@ func (s *svr) bgSaver() { } func (s *svr) flush() { - s.mu.Lock() - defer s.mu.Unlock() + accounts := s.allAccounts.clone() - if b, err := json.Marshal(&s.allAccounts); err != nil { + if b, err := json.Marshal(accounts); err != nil { grpclog.Errorf("failed to save data to %q", s.datafile) } else if err := ioutil.WriteFile(s.datafile, b, 0666); err != nil { grpclog.Errorf("failed to save data to %q", s.datafile) diff --git a/testing/cmd/bankdemo/support.pb.go b/testing/cmd/bankdemo/support.pb.go new file mode 100644 index 0000000..69a7c46 --- /dev/null +++ b/testing/cmd/bankdemo/support.pb.go @@ -0,0 +1,1250 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: support.proto + +package main + +import proto "github.com/golang/protobuf/proto" +import fmt "fmt" +import math "math" +import timestamp "github.com/golang/protobuf/ptypes/timestamp" + +import ( + context "golang.org/x/net/context" + grpc "google.golang.org/grpc" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package + +type Void int32 + +const ( + Void_VOID Void = 0 +) + +var Void_name = map[int32]string{ + 0: "VOID", +} +var Void_value = map[string]int32{ + "VOID": 0, +} + +func (x Void) String() string { + return proto.EnumName(Void_name, int32(x)) +} +func (Void) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_support_640cb5c436dbd37d, []int{0} +} + +type ChatCustomerRequest struct { + // Types that are valid to be assigned to Req: + // *ChatCustomerRequest_Init + // *ChatCustomerRequest_Msg + // *ChatCustomerRequest_HangUp + Req isChatCustomerRequest_Req `protobuf_oneof:"req"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ChatCustomerRequest) Reset() { *m = ChatCustomerRequest{} } +func (m *ChatCustomerRequest) String() string { return proto.CompactTextString(m) } +func (*ChatCustomerRequest) ProtoMessage() {} +func (*ChatCustomerRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_support_640cb5c436dbd37d, []int{0} +} +func (m *ChatCustomerRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ChatCustomerRequest.Unmarshal(m, b) +} +func (m *ChatCustomerRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ChatCustomerRequest.Marshal(b, m, deterministic) +} +func (dst *ChatCustomerRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ChatCustomerRequest.Merge(dst, src) +} +func (m *ChatCustomerRequest) XXX_Size() int { + return xxx_messageInfo_ChatCustomerRequest.Size(m) +} +func (m *ChatCustomerRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ChatCustomerRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ChatCustomerRequest proto.InternalMessageInfo + +type isChatCustomerRequest_Req interface { + isChatCustomerRequest_Req() +} + +type ChatCustomerRequest_Init struct { + Init *InitiateChat `protobuf:"bytes,1,opt,name=init,proto3,oneof"` +} +type ChatCustomerRequest_Msg struct { + Msg string `protobuf:"bytes,2,opt,name=msg,proto3,oneof"` +} +type ChatCustomerRequest_HangUp struct { + HangUp Void `protobuf:"varint,3,opt,name=hang_up,json=hangUp,proto3,enum=Void,oneof"` +} + +func (*ChatCustomerRequest_Init) isChatCustomerRequest_Req() {} +func (*ChatCustomerRequest_Msg) isChatCustomerRequest_Req() {} +func (*ChatCustomerRequest_HangUp) isChatCustomerRequest_Req() {} + +func (m *ChatCustomerRequest) GetReq() isChatCustomerRequest_Req { + if m != nil { + return m.Req + } + return nil +} + +func (m *ChatCustomerRequest) GetInit() *InitiateChat { + if x, ok := m.GetReq().(*ChatCustomerRequest_Init); ok { + return x.Init + } + return nil +} + +func (m *ChatCustomerRequest) GetMsg() string { + if x, ok := m.GetReq().(*ChatCustomerRequest_Msg); ok { + return x.Msg + } + return "" +} + +func (m *ChatCustomerRequest) GetHangUp() Void { + if x, ok := m.GetReq().(*ChatCustomerRequest_HangUp); ok { + return x.HangUp + } + return Void_VOID +} + +// XXX_OneofFuncs is for the internal use of the proto package. +func (*ChatCustomerRequest) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { + return _ChatCustomerRequest_OneofMarshaler, _ChatCustomerRequest_OneofUnmarshaler, _ChatCustomerRequest_OneofSizer, []interface{}{ + (*ChatCustomerRequest_Init)(nil), + (*ChatCustomerRequest_Msg)(nil), + (*ChatCustomerRequest_HangUp)(nil), + } +} + +func _ChatCustomerRequest_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { + m := msg.(*ChatCustomerRequest) + // req + switch x := m.Req.(type) { + case *ChatCustomerRequest_Init: + b.EncodeVarint(1<<3 | proto.WireBytes) + if err := b.EncodeMessage(x.Init); err != nil { + return err + } + case *ChatCustomerRequest_Msg: + b.EncodeVarint(2<<3 | proto.WireBytes) + b.EncodeStringBytes(x.Msg) + case *ChatCustomerRequest_HangUp: + b.EncodeVarint(3<<3 | proto.WireVarint) + b.EncodeVarint(uint64(x.HangUp)) + case nil: + default: + return fmt.Errorf("ChatCustomerRequest.Req has unexpected type %T", x) + } + return nil +} + +func _ChatCustomerRequest_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { + m := msg.(*ChatCustomerRequest) + switch tag { + case 1: // req.init + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + msg := new(InitiateChat) + err := b.DecodeMessage(msg) + m.Req = &ChatCustomerRequest_Init{msg} + return true, err + case 2: // req.msg + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeStringBytes() + m.Req = &ChatCustomerRequest_Msg{x} + return true, err + case 3: // req.hang_up + if wire != proto.WireVarint { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeVarint() + m.Req = &ChatCustomerRequest_HangUp{Void(x)} + return true, err + default: + return false, nil + } +} + +func _ChatCustomerRequest_OneofSizer(msg proto.Message) (n int) { + m := msg.(*ChatCustomerRequest) + // req + switch x := m.Req.(type) { + case *ChatCustomerRequest_Init: + s := proto.Size(x.Init) + n += 1 // tag and wire + n += proto.SizeVarint(uint64(s)) + n += s + case *ChatCustomerRequest_Msg: + n += 1 // tag and wire + n += proto.SizeVarint(uint64(len(x.Msg))) + n += len(x.Msg) + case *ChatCustomerRequest_HangUp: + n += 1 // tag and wire + n += proto.SizeVarint(uint64(x.HangUp)) + case nil: + default: + panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) + } + return n +} + +type InitiateChat struct { + ResumeSessionId string `protobuf:"bytes,1,opt,name=resume_session_id,json=resumeSessionId,proto3" json:"resume_session_id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *InitiateChat) Reset() { *m = InitiateChat{} } +func (m *InitiateChat) String() string { return proto.CompactTextString(m) } +func (*InitiateChat) ProtoMessage() {} +func (*InitiateChat) Descriptor() ([]byte, []int) { + return fileDescriptor_support_640cb5c436dbd37d, []int{1} +} +func (m *InitiateChat) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_InitiateChat.Unmarshal(m, b) +} +func (m *InitiateChat) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_InitiateChat.Marshal(b, m, deterministic) +} +func (dst *InitiateChat) XXX_Merge(src proto.Message) { + xxx_messageInfo_InitiateChat.Merge(dst, src) +} +func (m *InitiateChat) XXX_Size() int { + return xxx_messageInfo_InitiateChat.Size(m) +} +func (m *InitiateChat) XXX_DiscardUnknown() { + xxx_messageInfo_InitiateChat.DiscardUnknown(m) +} + +var xxx_messageInfo_InitiateChat proto.InternalMessageInfo + +func (m *InitiateChat) GetResumeSessionId() string { + if m != nil { + return m.ResumeSessionId + } + return "" +} + +type AgentMessage struct { + AgentName string `protobuf:"bytes,1,opt,name=agent_name,json=agentName,proto3" json:"agent_name,omitempty"` + Msg string `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *AgentMessage) Reset() { *m = AgentMessage{} } +func (m *AgentMessage) String() string { return proto.CompactTextString(m) } +func (*AgentMessage) ProtoMessage() {} +func (*AgentMessage) Descriptor() ([]byte, []int) { + return fileDescriptor_support_640cb5c436dbd37d, []int{2} +} +func (m *AgentMessage) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_AgentMessage.Unmarshal(m, b) +} +func (m *AgentMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_AgentMessage.Marshal(b, m, deterministic) +} +func (dst *AgentMessage) XXX_Merge(src proto.Message) { + xxx_messageInfo_AgentMessage.Merge(dst, src) +} +func (m *AgentMessage) XXX_Size() int { + return xxx_messageInfo_AgentMessage.Size(m) +} +func (m *AgentMessage) XXX_DiscardUnknown() { + xxx_messageInfo_AgentMessage.DiscardUnknown(m) +} + +var xxx_messageInfo_AgentMessage proto.InternalMessageInfo + +func (m *AgentMessage) GetAgentName() string { + if m != nil { + return m.AgentName + } + return "" +} + +func (m *AgentMessage) GetMsg() string { + if m != nil { + return m.Msg + } + return "" +} + +type ChatCustomerResponse struct { + // Types that are valid to be assigned to Resp: + // *ChatCustomerResponse_Session + // *ChatCustomerResponse_Msg + Resp isChatCustomerResponse_Resp `protobuf_oneof:"resp"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ChatCustomerResponse) Reset() { *m = ChatCustomerResponse{} } +func (m *ChatCustomerResponse) String() string { return proto.CompactTextString(m) } +func (*ChatCustomerResponse) ProtoMessage() {} +func (*ChatCustomerResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_support_640cb5c436dbd37d, []int{3} +} +func (m *ChatCustomerResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ChatCustomerResponse.Unmarshal(m, b) +} +func (m *ChatCustomerResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ChatCustomerResponse.Marshal(b, m, deterministic) +} +func (dst *ChatCustomerResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ChatCustomerResponse.Merge(dst, src) +} +func (m *ChatCustomerResponse) XXX_Size() int { + return xxx_messageInfo_ChatCustomerResponse.Size(m) +} +func (m *ChatCustomerResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ChatCustomerResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ChatCustomerResponse proto.InternalMessageInfo + +type isChatCustomerResponse_Resp interface { + isChatCustomerResponse_Resp() +} + +type ChatCustomerResponse_Session struct { + Session *Session `protobuf:"bytes,1,opt,name=session,proto3,oneof"` +} +type ChatCustomerResponse_Msg struct { + Msg *AgentMessage `protobuf:"bytes,2,opt,name=msg,proto3,oneof"` +} + +func (*ChatCustomerResponse_Session) isChatCustomerResponse_Resp() {} +func (*ChatCustomerResponse_Msg) isChatCustomerResponse_Resp() {} + +func (m *ChatCustomerResponse) GetResp() isChatCustomerResponse_Resp { + if m != nil { + return m.Resp + } + return nil +} + +func (m *ChatCustomerResponse) GetSession() *Session { + if x, ok := m.GetResp().(*ChatCustomerResponse_Session); ok { + return x.Session + } + return nil +} + +func (m *ChatCustomerResponse) GetMsg() *AgentMessage { + if x, ok := m.GetResp().(*ChatCustomerResponse_Msg); ok { + return x.Msg + } + return nil +} + +// XXX_OneofFuncs is for the internal use of the proto package. +func (*ChatCustomerResponse) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { + return _ChatCustomerResponse_OneofMarshaler, _ChatCustomerResponse_OneofUnmarshaler, _ChatCustomerResponse_OneofSizer, []interface{}{ + (*ChatCustomerResponse_Session)(nil), + (*ChatCustomerResponse_Msg)(nil), + } +} + +func _ChatCustomerResponse_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { + m := msg.(*ChatCustomerResponse) + // resp + switch x := m.Resp.(type) { + case *ChatCustomerResponse_Session: + b.EncodeVarint(1<<3 | proto.WireBytes) + if err := b.EncodeMessage(x.Session); err != nil { + return err + } + case *ChatCustomerResponse_Msg: + b.EncodeVarint(2<<3 | proto.WireBytes) + if err := b.EncodeMessage(x.Msg); err != nil { + return err + } + case nil: + default: + return fmt.Errorf("ChatCustomerResponse.Resp has unexpected type %T", x) + } + return nil +} + +func _ChatCustomerResponse_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { + m := msg.(*ChatCustomerResponse) + switch tag { + case 1: // resp.session + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + msg := new(Session) + err := b.DecodeMessage(msg) + m.Resp = &ChatCustomerResponse_Session{msg} + return true, err + case 2: // resp.msg + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + msg := new(AgentMessage) + err := b.DecodeMessage(msg) + m.Resp = &ChatCustomerResponse_Msg{msg} + return true, err + default: + return false, nil + } +} + +func _ChatCustomerResponse_OneofSizer(msg proto.Message) (n int) { + m := msg.(*ChatCustomerResponse) + // resp + switch x := m.Resp.(type) { + case *ChatCustomerResponse_Session: + s := proto.Size(x.Session) + n += 1 // tag and wire + n += proto.SizeVarint(uint64(s)) + n += s + case *ChatCustomerResponse_Msg: + s := proto.Size(x.Msg) + n += 1 // tag and wire + n += proto.SizeVarint(uint64(s)) + n += s + case nil: + default: + panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) + } + return n +} + +type ChatAgentRequest struct { + // Types that are valid to be assigned to Req: + // *ChatAgentRequest_Accept + // *ChatAgentRequest_Msg + // *ChatAgentRequest_LeaveSession + Req isChatAgentRequest_Req `protobuf_oneof:"req"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ChatAgentRequest) Reset() { *m = ChatAgentRequest{} } +func (m *ChatAgentRequest) String() string { return proto.CompactTextString(m) } +func (*ChatAgentRequest) ProtoMessage() {} +func (*ChatAgentRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_support_640cb5c436dbd37d, []int{4} +} +func (m *ChatAgentRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ChatAgentRequest.Unmarshal(m, b) +} +func (m *ChatAgentRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ChatAgentRequest.Marshal(b, m, deterministic) +} +func (dst *ChatAgentRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ChatAgentRequest.Merge(dst, src) +} +func (m *ChatAgentRequest) XXX_Size() int { + return xxx_messageInfo_ChatAgentRequest.Size(m) +} +func (m *ChatAgentRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ChatAgentRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ChatAgentRequest proto.InternalMessageInfo + +type isChatAgentRequest_Req interface { + isChatAgentRequest_Req() +} + +type ChatAgentRequest_Accept struct { + Accept *AcceptChat `protobuf:"bytes,1,opt,name=accept,proto3,oneof"` +} +type ChatAgentRequest_Msg struct { + Msg string `protobuf:"bytes,2,opt,name=msg,proto3,oneof"` +} +type ChatAgentRequest_LeaveSession struct { + LeaveSession Void `protobuf:"varint,3,opt,name=leave_session,json=leaveSession,proto3,enum=Void,oneof"` +} + +func (*ChatAgentRequest_Accept) isChatAgentRequest_Req() {} +func (*ChatAgentRequest_Msg) isChatAgentRequest_Req() {} +func (*ChatAgentRequest_LeaveSession) isChatAgentRequest_Req() {} + +func (m *ChatAgentRequest) GetReq() isChatAgentRequest_Req { + if m != nil { + return m.Req + } + return nil +} + +func (m *ChatAgentRequest) GetAccept() *AcceptChat { + if x, ok := m.GetReq().(*ChatAgentRequest_Accept); ok { + return x.Accept + } + return nil +} + +func (m *ChatAgentRequest) GetMsg() string { + if x, ok := m.GetReq().(*ChatAgentRequest_Msg); ok { + return x.Msg + } + return "" +} + +func (m *ChatAgentRequest) GetLeaveSession() Void { + if x, ok := m.GetReq().(*ChatAgentRequest_LeaveSession); ok { + return x.LeaveSession + } + return Void_VOID +} + +// XXX_OneofFuncs is for the internal use of the proto package. +func (*ChatAgentRequest) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { + return _ChatAgentRequest_OneofMarshaler, _ChatAgentRequest_OneofUnmarshaler, _ChatAgentRequest_OneofSizer, []interface{}{ + (*ChatAgentRequest_Accept)(nil), + (*ChatAgentRequest_Msg)(nil), + (*ChatAgentRequest_LeaveSession)(nil), + } +} + +func _ChatAgentRequest_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { + m := msg.(*ChatAgentRequest) + // req + switch x := m.Req.(type) { + case *ChatAgentRequest_Accept: + b.EncodeVarint(1<<3 | proto.WireBytes) + if err := b.EncodeMessage(x.Accept); err != nil { + return err + } + case *ChatAgentRequest_Msg: + b.EncodeVarint(2<<3 | proto.WireBytes) + b.EncodeStringBytes(x.Msg) + case *ChatAgentRequest_LeaveSession: + b.EncodeVarint(3<<3 | proto.WireVarint) + b.EncodeVarint(uint64(x.LeaveSession)) + case nil: + default: + return fmt.Errorf("ChatAgentRequest.Req has unexpected type %T", x) + } + return nil +} + +func _ChatAgentRequest_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { + m := msg.(*ChatAgentRequest) + switch tag { + case 1: // req.accept + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + msg := new(AcceptChat) + err := b.DecodeMessage(msg) + m.Req = &ChatAgentRequest_Accept{msg} + return true, err + case 2: // req.msg + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeStringBytes() + m.Req = &ChatAgentRequest_Msg{x} + return true, err + case 3: // req.leave_session + if wire != proto.WireVarint { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeVarint() + m.Req = &ChatAgentRequest_LeaveSession{Void(x)} + return true, err + default: + return false, nil + } +} + +func _ChatAgentRequest_OneofSizer(msg proto.Message) (n int) { + m := msg.(*ChatAgentRequest) + // req + switch x := m.Req.(type) { + case *ChatAgentRequest_Accept: + s := proto.Size(x.Accept) + n += 1 // tag and wire + n += proto.SizeVarint(uint64(s)) + n += s + case *ChatAgentRequest_Msg: + n += 1 // tag and wire + n += proto.SizeVarint(uint64(len(x.Msg))) + n += len(x.Msg) + case *ChatAgentRequest_LeaveSession: + n += 1 // tag and wire + n += proto.SizeVarint(uint64(x.LeaveSession)) + case nil: + default: + panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) + } + return n +} + +type AcceptChat struct { + SessionId string `protobuf:"bytes,1,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *AcceptChat) Reset() { *m = AcceptChat{} } +func (m *AcceptChat) String() string { return proto.CompactTextString(m) } +func (*AcceptChat) ProtoMessage() {} +func (*AcceptChat) Descriptor() ([]byte, []int) { + return fileDescriptor_support_640cb5c436dbd37d, []int{5} +} +func (m *AcceptChat) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_AcceptChat.Unmarshal(m, b) +} +func (m *AcceptChat) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_AcceptChat.Marshal(b, m, deterministic) +} +func (dst *AcceptChat) XXX_Merge(src proto.Message) { + xxx_messageInfo_AcceptChat.Merge(dst, src) +} +func (m *AcceptChat) XXX_Size() int { + return xxx_messageInfo_AcceptChat.Size(m) +} +func (m *AcceptChat) XXX_DiscardUnknown() { + xxx_messageInfo_AcceptChat.DiscardUnknown(m) +} + +var xxx_messageInfo_AcceptChat proto.InternalMessageInfo + +func (m *AcceptChat) GetSessionId() string { + if m != nil { + return m.SessionId + } + return "" +} + +type ChatEntry struct { + Date *timestamp.Timestamp `protobuf:"bytes,1,opt,name=date,proto3" json:"date,omitempty"` + // Types that are valid to be assigned to Entry: + // *ChatEntry_CustomerMsg + // *ChatEntry_AgentMsg + Entry isChatEntry_Entry `protobuf_oneof:"entry"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ChatEntry) Reset() { *m = ChatEntry{} } +func (m *ChatEntry) String() string { return proto.CompactTextString(m) } +func (*ChatEntry) ProtoMessage() {} +func (*ChatEntry) Descriptor() ([]byte, []int) { + return fileDescriptor_support_640cb5c436dbd37d, []int{6} +} +func (m *ChatEntry) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ChatEntry.Unmarshal(m, b) +} +func (m *ChatEntry) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ChatEntry.Marshal(b, m, deterministic) +} +func (dst *ChatEntry) XXX_Merge(src proto.Message) { + xxx_messageInfo_ChatEntry.Merge(dst, src) +} +func (m *ChatEntry) XXX_Size() int { + return xxx_messageInfo_ChatEntry.Size(m) +} +func (m *ChatEntry) XXX_DiscardUnknown() { + xxx_messageInfo_ChatEntry.DiscardUnknown(m) +} + +var xxx_messageInfo_ChatEntry proto.InternalMessageInfo + +type isChatEntry_Entry interface { + isChatEntry_Entry() +} + +type ChatEntry_CustomerMsg struct { + CustomerMsg string `protobuf:"bytes,2,opt,name=customer_msg,json=customerMsg,proto3,oneof"` +} +type ChatEntry_AgentMsg struct { + AgentMsg *AgentMessage `protobuf:"bytes,3,opt,name=agent_msg,json=agentMsg,proto3,oneof"` +} + +func (*ChatEntry_CustomerMsg) isChatEntry_Entry() {} +func (*ChatEntry_AgentMsg) isChatEntry_Entry() {} + +func (m *ChatEntry) GetEntry() isChatEntry_Entry { + if m != nil { + return m.Entry + } + return nil +} + +func (m *ChatEntry) GetDate() *timestamp.Timestamp { + if m != nil { + return m.Date + } + return nil +} + +func (m *ChatEntry) GetCustomerMsg() string { + if x, ok := m.GetEntry().(*ChatEntry_CustomerMsg); ok { + return x.CustomerMsg + } + return "" +} + +func (m *ChatEntry) GetAgentMsg() *AgentMessage { + if x, ok := m.GetEntry().(*ChatEntry_AgentMsg); ok { + return x.AgentMsg + } + return nil +} + +// XXX_OneofFuncs is for the internal use of the proto package. +func (*ChatEntry) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { + return _ChatEntry_OneofMarshaler, _ChatEntry_OneofUnmarshaler, _ChatEntry_OneofSizer, []interface{}{ + (*ChatEntry_CustomerMsg)(nil), + (*ChatEntry_AgentMsg)(nil), + } +} + +func _ChatEntry_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { + m := msg.(*ChatEntry) + // entry + switch x := m.Entry.(type) { + case *ChatEntry_CustomerMsg: + b.EncodeVarint(2<<3 | proto.WireBytes) + b.EncodeStringBytes(x.CustomerMsg) + case *ChatEntry_AgentMsg: + b.EncodeVarint(3<<3 | proto.WireBytes) + if err := b.EncodeMessage(x.AgentMsg); err != nil { + return err + } + case nil: + default: + return fmt.Errorf("ChatEntry.Entry has unexpected type %T", x) + } + return nil +} + +func _ChatEntry_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { + m := msg.(*ChatEntry) + switch tag { + case 2: // entry.customer_msg + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeStringBytes() + m.Entry = &ChatEntry_CustomerMsg{x} + return true, err + case 3: // entry.agent_msg + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + msg := new(AgentMessage) + err := b.DecodeMessage(msg) + m.Entry = &ChatEntry_AgentMsg{msg} + return true, err + default: + return false, nil + } +} + +func _ChatEntry_OneofSizer(msg proto.Message) (n int) { + m := msg.(*ChatEntry) + // entry + switch x := m.Entry.(type) { + case *ChatEntry_CustomerMsg: + n += 1 // tag and wire + n += proto.SizeVarint(uint64(len(x.CustomerMsg))) + n += len(x.CustomerMsg) + case *ChatEntry_AgentMsg: + s := proto.Size(x.AgentMsg) + n += 1 // tag and wire + n += proto.SizeVarint(uint64(s)) + n += s + case nil: + default: + panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) + } + return n +} + +type ChatAgentResponse struct { + // Types that are valid to be assigned to Resp: + // *ChatAgentResponse_AcceptedSession + // *ChatAgentResponse_Msg + // *ChatAgentResponse_SessionEnded + Resp isChatAgentResponse_Resp `protobuf_oneof:"resp"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ChatAgentResponse) Reset() { *m = ChatAgentResponse{} } +func (m *ChatAgentResponse) String() string { return proto.CompactTextString(m) } +func (*ChatAgentResponse) ProtoMessage() {} +func (*ChatAgentResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_support_640cb5c436dbd37d, []int{7} +} +func (m *ChatAgentResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ChatAgentResponse.Unmarshal(m, b) +} +func (m *ChatAgentResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ChatAgentResponse.Marshal(b, m, deterministic) +} +func (dst *ChatAgentResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ChatAgentResponse.Merge(dst, src) +} +func (m *ChatAgentResponse) XXX_Size() int { + return xxx_messageInfo_ChatAgentResponse.Size(m) +} +func (m *ChatAgentResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ChatAgentResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ChatAgentResponse proto.InternalMessageInfo + +type isChatAgentResponse_Resp interface { + isChatAgentResponse_Resp() +} + +type ChatAgentResponse_AcceptedSession struct { + AcceptedSession *Session `protobuf:"bytes,1,opt,name=accepted_session,json=acceptedSession,proto3,oneof"` +} +type ChatAgentResponse_Msg struct { + Msg *ChatEntry `protobuf:"bytes,2,opt,name=msg,proto3,oneof"` +} +type ChatAgentResponse_SessionEnded struct { + SessionEnded Void `protobuf:"varint,3,opt,name=session_ended,json=sessionEnded,proto3,enum=Void,oneof"` +} + +func (*ChatAgentResponse_AcceptedSession) isChatAgentResponse_Resp() {} +func (*ChatAgentResponse_Msg) isChatAgentResponse_Resp() {} +func (*ChatAgentResponse_SessionEnded) isChatAgentResponse_Resp() {} + +func (m *ChatAgentResponse) GetResp() isChatAgentResponse_Resp { + if m != nil { + return m.Resp + } + return nil +} + +func (m *ChatAgentResponse) GetAcceptedSession() *Session { + if x, ok := m.GetResp().(*ChatAgentResponse_AcceptedSession); ok { + return x.AcceptedSession + } + return nil +} + +func (m *ChatAgentResponse) GetMsg() *ChatEntry { + if x, ok := m.GetResp().(*ChatAgentResponse_Msg); ok { + return x.Msg + } + return nil +} + +func (m *ChatAgentResponse) GetSessionEnded() Void { + if x, ok := m.GetResp().(*ChatAgentResponse_SessionEnded); ok { + return x.SessionEnded + } + return Void_VOID +} + +// XXX_OneofFuncs is for the internal use of the proto package. +func (*ChatAgentResponse) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { + return _ChatAgentResponse_OneofMarshaler, _ChatAgentResponse_OneofUnmarshaler, _ChatAgentResponse_OneofSizer, []interface{}{ + (*ChatAgentResponse_AcceptedSession)(nil), + (*ChatAgentResponse_Msg)(nil), + (*ChatAgentResponse_SessionEnded)(nil), + } +} + +func _ChatAgentResponse_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { + m := msg.(*ChatAgentResponse) + // resp + switch x := m.Resp.(type) { + case *ChatAgentResponse_AcceptedSession: + b.EncodeVarint(1<<3 | proto.WireBytes) + if err := b.EncodeMessage(x.AcceptedSession); err != nil { + return err + } + case *ChatAgentResponse_Msg: + b.EncodeVarint(2<<3 | proto.WireBytes) + if err := b.EncodeMessage(x.Msg); err != nil { + return err + } + case *ChatAgentResponse_SessionEnded: + b.EncodeVarint(3<<3 | proto.WireVarint) + b.EncodeVarint(uint64(x.SessionEnded)) + case nil: + default: + return fmt.Errorf("ChatAgentResponse.Resp has unexpected type %T", x) + } + return nil +} + +func _ChatAgentResponse_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { + m := msg.(*ChatAgentResponse) + switch tag { + case 1: // resp.accepted_session + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + msg := new(Session) + err := b.DecodeMessage(msg) + m.Resp = &ChatAgentResponse_AcceptedSession{msg} + return true, err + case 2: // resp.msg + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + msg := new(ChatEntry) + err := b.DecodeMessage(msg) + m.Resp = &ChatAgentResponse_Msg{msg} + return true, err + case 3: // resp.session_ended + if wire != proto.WireVarint { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeVarint() + m.Resp = &ChatAgentResponse_SessionEnded{Void(x)} + return true, err + default: + return false, nil + } +} + +func _ChatAgentResponse_OneofSizer(msg proto.Message) (n int) { + m := msg.(*ChatAgentResponse) + // resp + switch x := m.Resp.(type) { + case *ChatAgentResponse_AcceptedSession: + s := proto.Size(x.AcceptedSession) + n += 1 // tag and wire + n += proto.SizeVarint(uint64(s)) + n += s + case *ChatAgentResponse_Msg: + s := proto.Size(x.Msg) + n += 1 // tag and wire + n += proto.SizeVarint(uint64(s)) + n += s + case *ChatAgentResponse_SessionEnded: + n += 1 // tag and wire + n += proto.SizeVarint(uint64(x.SessionEnded)) + case nil: + default: + panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) + } + return n +} + +type Session struct { + SessionId string `protobuf:"bytes,1,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"` + CustomerName string `protobuf:"bytes,2,opt,name=customer_name,json=customerName,proto3" json:"customer_name,omitempty"` + History []*ChatEntry `protobuf:"bytes,3,rep,name=history,proto3" json:"history,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Session) Reset() { *m = Session{} } +func (m *Session) String() string { return proto.CompactTextString(m) } +func (*Session) ProtoMessage() {} +func (*Session) Descriptor() ([]byte, []int) { + return fileDescriptor_support_640cb5c436dbd37d, []int{8} +} +func (m *Session) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Session.Unmarshal(m, b) +} +func (m *Session) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Session.Marshal(b, m, deterministic) +} +func (dst *Session) XXX_Merge(src proto.Message) { + xxx_messageInfo_Session.Merge(dst, src) +} +func (m *Session) XXX_Size() int { + return xxx_messageInfo_Session.Size(m) +} +func (m *Session) XXX_DiscardUnknown() { + xxx_messageInfo_Session.DiscardUnknown(m) +} + +var xxx_messageInfo_Session proto.InternalMessageInfo + +func (m *Session) GetSessionId() string { + if m != nil { + return m.SessionId + } + return "" +} + +func (m *Session) GetCustomerName() string { + if m != nil { + return m.CustomerName + } + return "" +} + +func (m *Session) GetHistory() []*ChatEntry { + if m != nil { + return m.History + } + return nil +} + +func init() { + proto.RegisterType((*ChatCustomerRequest)(nil), "ChatCustomerRequest") + proto.RegisterType((*InitiateChat)(nil), "InitiateChat") + proto.RegisterType((*AgentMessage)(nil), "AgentMessage") + proto.RegisterType((*ChatCustomerResponse)(nil), "ChatCustomerResponse") + proto.RegisterType((*ChatAgentRequest)(nil), "ChatAgentRequest") + proto.RegisterType((*AcceptChat)(nil), "AcceptChat") + proto.RegisterType((*ChatEntry)(nil), "ChatEntry") + proto.RegisterType((*ChatAgentResponse)(nil), "ChatAgentResponse") + proto.RegisterType((*Session)(nil), "Session") + proto.RegisterEnum("Void", Void_name, Void_value) +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// SupportClient is the client API for Support service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type SupportClient interface { + // ChatCustomer is used by a customer-facing app to send the customer's messages + // to a chat session. The customer is how initiates and terminates (via "hangup") + // a chat session. Only customers may invoke this method (e.g. requests must + // include customer auth credentials). + ChatCustomer(ctx context.Context, opts ...grpc.CallOption) (Support_ChatCustomerClient, error) + // ChatAgent is used by an agent-facing app to allow an agent to reply to a + // customer's messages in a chat session. The agent may accept a chat session, + // which defaults to the session awaiting an agent for the longest period of time + // (FIFO queue). + ChatAgent(ctx context.Context, opts ...grpc.CallOption) (Support_ChatAgentClient, error) +} + +type supportClient struct { + cc *grpc.ClientConn +} + +func NewSupportClient(cc *grpc.ClientConn) SupportClient { + return &supportClient{cc} +} + +func (c *supportClient) ChatCustomer(ctx context.Context, opts ...grpc.CallOption) (Support_ChatCustomerClient, error) { + stream, err := c.cc.NewStream(ctx, &_Support_serviceDesc.Streams[0], "/Support/ChatCustomer", opts...) + if err != nil { + return nil, err + } + x := &supportChatCustomerClient{stream} + return x, nil +} + +type Support_ChatCustomerClient interface { + Send(*ChatCustomerRequest) error + Recv() (*ChatCustomerResponse, error) + grpc.ClientStream +} + +type supportChatCustomerClient struct { + grpc.ClientStream +} + +func (x *supportChatCustomerClient) Send(m *ChatCustomerRequest) error { + return x.ClientStream.SendMsg(m) +} + +func (x *supportChatCustomerClient) Recv() (*ChatCustomerResponse, error) { + m := new(ChatCustomerResponse) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +func (c *supportClient) ChatAgent(ctx context.Context, opts ...grpc.CallOption) (Support_ChatAgentClient, error) { + stream, err := c.cc.NewStream(ctx, &_Support_serviceDesc.Streams[1], "/Support/ChatAgent", opts...) + if err != nil { + return nil, err + } + x := &supportChatAgentClient{stream} + return x, nil +} + +type Support_ChatAgentClient interface { + Send(*ChatAgentRequest) error + Recv() (*ChatAgentResponse, error) + grpc.ClientStream +} + +type supportChatAgentClient struct { + grpc.ClientStream +} + +func (x *supportChatAgentClient) Send(m *ChatAgentRequest) error { + return x.ClientStream.SendMsg(m) +} + +func (x *supportChatAgentClient) Recv() (*ChatAgentResponse, error) { + m := new(ChatAgentResponse) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +// SupportServer is the server API for Support service. +type SupportServer interface { + // ChatCustomer is used by a customer-facing app to send the customer's messages + // to a chat session. The customer is how initiates and terminates (via "hangup") + // a chat session. Only customers may invoke this method (e.g. requests must + // include customer auth credentials). + ChatCustomer(Support_ChatCustomerServer) error + // ChatAgent is used by an agent-facing app to allow an agent to reply to a + // customer's messages in a chat session. The agent may accept a chat session, + // which defaults to the session awaiting an agent for the longest period of time + // (FIFO queue). + ChatAgent(Support_ChatAgentServer) error +} + +func RegisterSupportServer(s *grpc.Server, srv SupportServer) { + s.RegisterService(&_Support_serviceDesc, srv) +} + +func _Support_ChatCustomer_Handler(srv interface{}, stream grpc.ServerStream) error { + return srv.(SupportServer).ChatCustomer(&supportChatCustomerServer{stream}) +} + +type Support_ChatCustomerServer interface { + Send(*ChatCustomerResponse) error + Recv() (*ChatCustomerRequest, error) + grpc.ServerStream +} + +type supportChatCustomerServer struct { + grpc.ServerStream +} + +func (x *supportChatCustomerServer) Send(m *ChatCustomerResponse) error { + return x.ServerStream.SendMsg(m) +} + +func (x *supportChatCustomerServer) Recv() (*ChatCustomerRequest, error) { + m := new(ChatCustomerRequest) + if err := x.ServerStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +func _Support_ChatAgent_Handler(srv interface{}, stream grpc.ServerStream) error { + return srv.(SupportServer).ChatAgent(&supportChatAgentServer{stream}) +} + +type Support_ChatAgentServer interface { + Send(*ChatAgentResponse) error + Recv() (*ChatAgentRequest, error) + grpc.ServerStream +} + +type supportChatAgentServer struct { + grpc.ServerStream +} + +func (x *supportChatAgentServer) Send(m *ChatAgentResponse) error { + return x.ServerStream.SendMsg(m) +} + +func (x *supportChatAgentServer) Recv() (*ChatAgentRequest, error) { + m := new(ChatAgentRequest) + if err := x.ServerStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +var _Support_serviceDesc = grpc.ServiceDesc{ + ServiceName: "Support", + HandlerType: (*SupportServer)(nil), + Methods: []grpc.MethodDesc{}, + Streams: []grpc.StreamDesc{ + { + StreamName: "ChatCustomer", + Handler: _Support_ChatCustomer_Handler, + ServerStreams: true, + ClientStreams: true, + }, + { + StreamName: "ChatAgent", + Handler: _Support_ChatAgent_Handler, + ServerStreams: true, + ClientStreams: true, + }, + }, + Metadata: "support.proto", +} + +func init() { proto.RegisterFile("support.proto", fileDescriptor_support_640cb5c436dbd37d) } + +var fileDescriptor_support_640cb5c436dbd37d = []byte{ + // 571 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x94, 0x4f, 0x6f, 0xd3, 0x40, + 0x10, 0xc5, 0x63, 0xec, 0xc6, 0xcd, 0x24, 0xa1, 0xc9, 0x52, 0xa4, 0x28, 0x12, 0x10, 0x9c, 0x22, + 0x45, 0x05, 0x6d, 0x51, 0x10, 0x1c, 0xb8, 0x54, 0x4d, 0xa9, 0x94, 0x1c, 0x02, 0x92, 0x0b, 0x3d, + 0x70, 0xb1, 0xb6, 0xf1, 0xe0, 0x58, 0xaa, 0xff, 0xd4, 0xbb, 0x06, 0xf5, 0xda, 0x2f, 0xc1, 0x95, + 0x8f, 0x8a, 0x76, 0xbd, 0x76, 0xdd, 0x26, 0x70, 0xdc, 0x99, 0x67, 0xcf, 0xdb, 0xdf, 0x3c, 0x1b, + 0xba, 0x3c, 0x4f, 0xd3, 0x24, 0x13, 0x34, 0xcd, 0x12, 0x91, 0x0c, 0x5f, 0x04, 0x49, 0x12, 0x5c, + 0xe1, 0x91, 0x3a, 0x5d, 0xe6, 0x3f, 0x8e, 0x44, 0x18, 0x21, 0x17, 0x2c, 0x4a, 0x0b, 0x81, 0xf3, + 0x0b, 0x9e, 0x9c, 0xae, 0x99, 0x38, 0xcd, 0xb9, 0x48, 0x22, 0xcc, 0x5c, 0xbc, 0xce, 0x91, 0x0b, + 0x32, 0x06, 0x2b, 0x8c, 0x43, 0x31, 0x30, 0x46, 0xc6, 0xa4, 0x3d, 0xed, 0xd2, 0x45, 0x1c, 0x8a, + 0x90, 0x09, 0x94, 0xda, 0x79, 0xc3, 0x55, 0x4d, 0x42, 0xc0, 0x8c, 0x78, 0x30, 0x78, 0x34, 0x32, + 0x26, 0xad, 0x79, 0xc3, 0x95, 0x07, 0x32, 0x02, 0x7b, 0xcd, 0xe2, 0xc0, 0xcb, 0xd3, 0x81, 0x39, + 0x32, 0x26, 0x8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, 0xc6, 0x52, + 0xe4, 0x73, 0xb3, 0xe6, 0x77, 0x2b, 0x62, 0x61, 0x7c, 0xd9, 0x54, 0x61, 0x79, 0xf7, 0x37, 0x00, + 0x00, 0xff, 0xff, 0x00, 0xf3, 0x29, 0x6f, 0x9a, 0x04, 0x00, 0x00, +} diff --git a/testing/cmd/bankdemo/support.proto b/testing/cmd/bankdemo/support.proto new file mode 100644 index 0000000..567b165 --- /dev/null +++ b/testing/cmd/bankdemo/support.proto @@ -0,0 +1,118 @@ +syntax = "proto3"; + +option go_package = "main"; + +import "google/protobuf/timestamp.proto"; + +// Support provides an interactive chat service, for customers to interact with +// the bank's support agents. A single stream, for either of the two methods, is +// a stateful connection to a single "chat session". Streams are initially disconnected +// (not part of any session). A stream must be disconnected from a session (via customer +// hang up or via agent leaving a session) before it can be connected to a new one. +service Support { + // ChatCustomer is used by a customer-facing app to send the customer's messages + // to a chat session. The customer is how initiates and terminates (via "hangup") + // a chat session. Only customers may invoke this method (e.g. requests must + // include customer auth credentials). + rpc ChatCustomer(stream ChatCustomerRequest) returns (stream ChatCustomerResponse); + // ChatAgent is used by an agent-facing app to allow an agent to reply to a + // customer's messages in a chat session. The agent may accept a chat session, + // which defaults to the session awaiting an agent for the longest period of time + // (FIFO queue). + rpc ChatAgent(stream ChatAgentRequest) returns (stream ChatAgentResponse); +} + +enum Void { + VOID = 0; +} + +message ChatCustomerRequest { + oneof req { + // init is used when a chat stream is not part of a + // chat session. This is a stream's initial state, as well as + // the state after a "hang_up" request is sent. This creates + // a new state session or resumes an existing one. + InitiateChat init = 1; + // msg is used to send the customer's messages to support + // agents. + string msg = 2; + // hang_up is used to terminate a chat session. If a stream + // is broken, but the session was not terminated, the client + // may initiate a new stream and use init to resume that + // session. Sessions are not terminated unless done so + // explicitly via sending this kind of request on the stream. + Void hang_up = 3; + } +} + +message InitiateChat { + string resume_session_id = 1; +} + +message AgentMessage { + string agent_name = 1; + string msg = 2; +} + +message ChatCustomerResponse { + oneof resp { + // session is sent from the server when the stream is connected + // to a chat session. This happens after an init request is sent + // and the stream is connected to either a new or resumed session. + Session session = 1; + // msg is sent from the server to convey agents' messages to the + // customer. + AgentMessage msg = 2; + } +} + +message ChatAgentRequest { + oneof req { + // accept is used when an agent wants to join a customer chat + // session. It can be used to connect to a specific session (by + // ID), or to just accept the session for which the customer has + // been waiting the longest (e.g. poll a FIFO queue of sessions + // awaiting a support agent). It is possible for multiple agents + // to be connected to the same chat session. + AcceptChat accept = 1; + // msg is used to send a message to the customer. It will also be + // delivered to any other connected support agents. + string msg = 2; + // leave_session allows an agent to exit a chat session. They can + // always re-enter later by sending an accept message for that + // session ID. + Void leave_session = 3; + } +} + +message AcceptChat { + string session_id = 1; +} + +message ChatEntry { + google.protobuf.Timestamp date = 1; + oneof entry { + string customer_msg = 2; + AgentMessage agent_msg = 3; + } +} + +message ChatAgentResponse { + oneof resp { + // accepted_session provides the detail of a chat session. The server + // sends this message after the agent has accepted a chat session. + Session accepted_session = 1; + // msg is sent by the server when the customer, or another support + // agent, sends a message in stream's current session. + ChatEntry msg = 2; + // session_ended notifies the support agent that their currently + // connected chat session has been terminated by the customer. + Void session_ended = 3; + } +} + +message Session { + string session_id = 1; + string customer_name = 2; + repeated ChatEntry history = 3; +}