Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create request/response #44

Closed
p53 opened this issue Jun 10, 2020 · 1 comment
Closed

Create request/response #44

p53 opened this issue Jun 10, 2020 · 1 comment
Labels
question Further information is requested

Comments

@p53
Copy link

p53 commented Jun 10, 2020

i thought about creating request/response programatically with Struct and Schema, i think it could be useful for testing purposes as well for creating responses nicely
I had these problems:

  1. Struct doesn't accept Schema, it just accepts *schema and NewSchema returns Schema, i created new constructor NewSchemaStruct which returns *schema and created request:
	schemaTopicMetadata := NewSchemaStruct("topic_metadata_v0",
		&field{name: "key", ty: typeInt16},
		&field{name: "version", ty: typeInt16},
		&field{name: "correlation_id", ty: typeInt32},
		&field{name: "client_id", ty: typeStr},
		&array{name: "topic", ty: typeStr},
	)

	topicMetadata := Struct{
		schema: schemaTopicMetadata,
		values: make([]interface{}, 0),
	}

	topicMetadata.values = append(topicMetadata.values, int16(0))
	topicMetadata.values = append(topicMetadata.values, int16(0))
	topicMetadata.values = append(topicMetadata.values, int32(0))
	topicMetadata.values = append(topicMetadata.values, "custom")
	arr := make([]interface{}, 0)
	arr = append(arr, "topic1")
	arr = append(arr, "topic2")
	topicMetadata.values = append(topicMetadata.values, arr)

	encoded, err := EncodeSchema(&topicMetadata, schemaTopicMetadata)
  1. Second problem, when i have schema created already i cannot retrieve schema of some of it's fields e.g.:
        type FetchRequest_v0 struct {}
        func (*f FetchRequest_v0) getSchema() Schema {
	partitionSchema := NewSchema("partition_schema",
		&field{name: "partition", ty: typeInt32},
		&field{name: "fetch_offset", ty: typeInt64},
		&field{name: "partition_max_bytes", ty: typeInt32},
	)

	topicSchema := NewSchema("topic_schema",
		&field{name: "topic_name", ty: typeStr},
		&array{name: "partitions", ty: partitionSchema},
	)

	schemaFetch := NewSchema("fetch_v0",
		&field{name: "key", ty: typeInt16},
		&field{name: "version", ty: typeInt16},
		&field{name: "correlation_id", ty: typeInt32},
		&field{name: "client_id", ty: typeStr},
		&field{name: "reaplica_id", ty: typeInt32},
		&field{name: "max_wait_time", ty: typeInt32},
		&field{name: "min_bytes", ty: typeInt32},
		&array{name: "topics", ty: topicSchema},
	)

        return schemaFetch
       }

       req := &FetchRequest_v0{}
       topicSchema := req.GetSchema().fieldsByName["topics"].def.ty - ???? (cannot use this because in Schema constructor 
we assert fields as Fields in NewSchema - Fields doesn't have method for schema gathering)
	someStruct := Struct{
		schema: topicSchema,
		values: make([]interface{}, 0),
	}
        ....add some values to someStruct
  1. We could solve problem when Struct would accept Schema but then we would need to add additional methods to Schema interface for getting fieldByName and fields - this occurs on quite many places in code
  2. to solve this we could add additional method to Field interface - e.g. GetSchema and implement on array, field etc....types - this would be quite non-intrusive
  3. i would like to ask also about EncodeSchema function, requires Struct (which itself contains schema) and also Schema (which practically contains same info as schema in Struct) it is duplication of information, not sure if it is needed

I can create pull requests but i would like to discuss it first as i don't know the code so deeply

@everesio
Copy link
Contributor

please create a PR with changes you think are reasonable (with tests) and I will have a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants