Skip to content

Commit

Permalink
Revert "Added method OriginalString"
Browse files Browse the repository at this point in the history
This reverts commit 083c889.
  • Loading branch information
Elia Bracci committed Oct 20, 2023
1 parent 083c889 commit b70ab6a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
25 changes: 8 additions & 17 deletions protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,13 @@ type Protocol struct {
doc string

hash string

originalString string
}

// NewProtocol creates a protocol instance.
func NewProtocol(
name, namepsace string,
types []NamedSchema,
messages map[string]*Message,
protocolString string,
opts ...ProtocolOption,
) (*Protocol, error) {
var cfg protocolConfig
Expand All @@ -72,12 +69,11 @@ func NewProtocol(
}

p := &Protocol{
name: n,
properties: newProperties(cfg.props, protocolReserved),
types: types,
messages: messages,
doc: cfg.doc,
originalString: protocolString,
name: n,
properties: newProperties(cfg.props, protocolReserved),
types: types,
messages: messages,
doc: cfg.doc,
}

b := md5.Sum([]byte(p.String()))
Expand Down Expand Up @@ -106,11 +102,6 @@ func (p *Protocol) Types() []NamedSchema {
return p.types
}

// OriginalString returns the original string of the protocol.
func (p *Protocol) OriginalString() string {
return p.originalString
}

// String returns the canonical form of the protocol.
func (p *Protocol) String() string {
types := ""
Expand Down Expand Up @@ -240,7 +231,7 @@ func ParseProtocol(protocol string) (*Protocol, error) {
}

seen := seenCache{}
return parseProtocol(m, seen, cache, protocol)
return parseProtocol(m, seen, cache)
}

type protocol struct {
Expand All @@ -252,7 +243,7 @@ type protocol struct {
Props map[string]any `mapstructure:",remain"`
}

func parseProtocol(m map[string]any, seen seenCache, cache *SchemaCache, protocolString string) (*Protocol, error) {
func parseProtocol(m map[string]any, seen seenCache, cache *SchemaCache) (*Protocol, error) {
var (
p protocol
meta mapstructure.Metadata
Expand Down Expand Up @@ -288,7 +279,7 @@ func parseProtocol(m map[string]any, seen seenCache, cache *SchemaCache, protoco
}
}

return NewProtocol(p.Protocol, p.Namespace, types, messages, protocolString, WithProtoDoc(p.Doc), WithProtoProps(p.Props))
return NewProtocol(p.Protocol, p.Namespace, types, messages, WithProtoDoc(p.Doc), WithProtoProps(p.Props))
}

func parseProtocolTypes(namespace string, types []any, seen seenCache, cache *SchemaCache) ([]NamedSchema, error) {
Expand Down
11 changes: 1 addition & 10 deletions protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,11 @@ func TestMustParseProtocol_PanicsOnError(t *testing.T) {
}

func TestNewProtocol_ValidatesName(t *testing.T) {
_, err := avro.NewProtocol("0test", "", nil, nil, "")
_, err := avro.NewProtocol("0test", "", nil, nil)

assert.Error(t, err)
}

func TestNewProtocol_OriginalString(t *testing.T) {
schema := `{"protocol":"test", "namespace": "org.hamba.avro", "messages":{"test":{"request": [{"name": "foobar", "type": "string"}]}}}`

proto, err := avro.ParseProtocol(schema)

assert.NoError(t, err)
assert.Equal(t, schema, proto.OriginalString())
}

func TestNewMessage(t *testing.T) {
field, _ := avro.NewField("test", avro.NewPrimitiveSchema(avro.String, nil))
fields := []*avro.Field{field}
Expand Down

0 comments on commit b70ab6a

Please sign in to comment.