You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fory.apache.org by "junjiexh (via GitHub)" <gi...@apache.org> on 2025/09/12 13:05:33 UTC
[PR] feat(go): Implement compatible mode with metashare mode [fory]
junjiexh opened a new pull request, #2607:
URL: https://github.com/apache/fory/pull/2607
## Why?
Type-forward and backward-compatible serialization are crucial for online services where different services update their data schemas and deploy at different times. This ensures that a service running an older schema can still communicate with a service using a newer one, and vice versa.This PR is part of the work of it. The previous PR is #2554 , and following pr are still work in process.
## What does this PR do?
This PR implements a metashare mode for the fory-go.
Specifically, it:
Provides a user option to enable compatible mode.
If compatible mode is enabled, the serialization process not only serializes the data but also its detailed type information into a binary format.
The reading peer, if compatible mode is enabled, will first attempt to read this type information before deserializing the data. This allows it to handle data serialized with a different schema.
This implementation is heavily inspired by the existing Java and Python implementations, ensuring consistency across framework.
All progress and todos:
- [x] metadata encoding and decoding
- [x] Integrate into the main flow to enable metadata sharing
- [ ] Add support for collection types (map, slice, set, etc.)
- [ ] Add support for compressed type definitions
- [ ] Test with python
## Related issues
#2192
## Does this PR introduce any user-facing change?
<!--
If any user-facing interface changes, please [open an issue](https://github.com/apache/fory/issues/new/choose) describing the need to do so and update the document if necessary.
Delete section if not applicable.
-->
- [x] Does this PR introduce any public API change? Yes.
- [x] Does this PR introduce any binary protocol compatibility change? No.
## Benchmark
<!--
When the PR has an impact on performance (if you don't know whether the PR will have an impact on performance, you can submit the PR first, and if it will have impact on performance, the code reviewer will explain it), be sure to attach a benchmark data here.
Delete section if not applicable.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(go): Implement compatible mode with metashare mode [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2607:
URL: https://github.com/apache/fory/pull/2607#discussion_r2348211527
##########
go/fory/fory.go:
##########
@@ -24,13 +24,53 @@ import (
"sync"
)
-func NewFory(referenceTracking bool) *Fory {
+// ForyOption represents a configuration option for Fory instances
+type ForyOption func(*Fory)
Review Comment:
Maybe we don't need the Fory prefix.
And please document it that this is the functional options. Not everyone knows it. And we also need to update the readme for this
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(go): Implement compatible mode with metashare mode [fory]
Posted by "junjiexh (via GitHub)" <gi...@apache.org>.
junjiexh commented on code in PR #2607:
URL: https://github.com/apache/fory/pull/2607#discussion_r2344221039
##########
go/fory/type.go:
##########
@@ -597,15 +604,10 @@ func (r *typeResolver) getTypeInfo(value reflect.Value, create bool) (TypeInfo,
}
clean := strings.TrimPrefix(rawInfo, "*@")
clean = strings.TrimPrefix(clean, "@")
+ typeName = clean
if idx := strings.LastIndex(clean, "."); idx != -1 {
pkgPath = clean[:idx]
- } else {
- pkgPath = clean
- }
- if typ.Kind() == reflect.Ptr {
- typeName = typ.Elem().Name()
- } else {
- typeName = typ.Name()
+ typeName = clean[idx+1:]
Review Comment:
Here fix a bug that cause user specific tag not work on typeName(In the past, if user register a type called C with 'A.B', the typeName and pkgName will be 'A.C')
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(go): Implement compatible mode with metashare mode [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2607:
URL: https://github.com/apache/fory/pull/2607#discussion_r2348009074
##########
go/fory/fory_metashare_test.go:
##########
@@ -0,0 +1,181 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package fory
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+// Test structs for metashare testing
+
+type SimpleDataClass struct {
+ Name string `fory:"name"`
+ Age int32 `fory:"age"`
+ Active bool `fory:"active"`
+}
+type ExtendedDataClass struct {
+ Name string `fory:"name"`
+ Age int32 `fory:"age"`
+ Active bool `fory:"active"`
+ Email string `fory:"email"` // Additional field
+}
+
+type ReducedDataClass struct {
+ Name string `fory:"name"`
+ Age int32 `fory:"age"`
+ // Missing 'active' field
+}
+
+func TestMetaShareEnabled(t *testing.T) {
+ fory := NewForyWithOptions(WithCompatible(true))
+
+ assert.True(t, fory.compatible, "Expected compatible mode to be enabled")
+ assert.NotNil(t, fory.metaContext, "Expected metaContext to be initialized when compatible=true")
+ assert.True(t, fory.metaContext.IsScopedMetaShareEnabled(), "Expected scoped meta share to be enabled by default when compatible=true")
+}
+
+func TestMetaShareDisabled(t *testing.T) {
+ fory := NewForyWithOptions(WithCompatible(false))
+
+ assert.False(t, fory.compatible, "Expected compatible mode to be disabled")
+ assert.Nil(t, fory.metaContext, "Expected metaContext to be nil when compatible=false")
+}
+
+func TestSimpleDataClassSerialization(t *testing.T) {
+ fory := NewForyWithOptions(WithCompatible(true))
+
+ // Register the struct
+ err := fory.RegisterTagType("SimpleDataClass", SimpleDataClass{})
Review Comment:
@pandalee99 This API should be removed already, and replaced by:
```go
func (r *typeResolver) registerNamedType(
type_ reflect.Type,
namespace string,
typeName string
)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(go): Implement compatible mode with metashare mode [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2607:
URL: https://github.com/apache/fory/pull/2607#discussion_r2348012290
##########
go/fory/fory_metashare_test.go:
##########
@@ -0,0 +1,181 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package fory
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+// Test structs for metashare testing
+
+type SimpleDataClass struct {
+ Name string `fory:"name"`
+ Age int32 `fory:"age"`
+ Active bool `fory:"active"`
+}
+type ExtendedDataClass struct {
+ Name string `fory:"name"`
+ Age int32 `fory:"age"`
+ Active bool `fory:"active"`
+ Email string `fory:"email"` // Additional field
+}
+
+type ReducedDataClass struct {
+ Name string `fory:"name"`
+ Age int32 `fory:"age"`
+ // Missing 'active' field
+}
+
+func TestMetaShareEnabled(t *testing.T) {
+ fory := NewForyWithOptions(WithCompatible(true))
+
+ assert.True(t, fory.compatible, "Expected compatible mode to be enabled")
+ assert.NotNil(t, fory.metaContext, "Expected metaContext to be initialized when compatible=true")
+ assert.True(t, fory.metaContext.IsScopedMetaShareEnabled(), "Expected scoped meta share to be enabled by default when compatible=true")
+}
+
+func TestMetaShareDisabled(t *testing.T) {
+ fory := NewForyWithOptions(WithCompatible(false))
+
+ assert.False(t, fory.compatible, "Expected compatible mode to be disabled")
+ assert.Nil(t, fory.metaContext, "Expected metaContext to be nil when compatible=false")
+}
+
+func TestSimpleDataClassSerialization(t *testing.T) {
+ fory := NewForyWithOptions(WithCompatible(true))
+
+ // Register the struct
+ err := fory.RegisterTagType("SimpleDataClass", SimpleDataClass{})
Review Comment:
@junjiexh Let's create an issue for this and update the API call in future after the API has been updated
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(go): Implement compatible mode with metashare mode [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2607:
URL: https://github.com/apache/fory/pull/2607#discussion_r2347999165
##########
go/fory/fory_metashare_test.go:
##########
@@ -0,0 +1,181 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package fory
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+// Test structs for metashare testing
+
+type SimpleDataClass struct {
+ Name string `fory:"name"`
Review Comment:
why do we need to add `tag` here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(go): Implement compatible mode with metashare mode [fory]
Posted by "junjiexh (via GitHub)" <gi...@apache.org>.
junjiexh commented on code in PR #2607:
URL: https://github.com/apache/fory/pull/2607#discussion_r2347999979
##########
go/fory/fory.go:
##########
@@ -24,13 +24,53 @@ import (
"sync"
)
+// ForyOption represents a configuration option for Fory instances
+type ForyOption func(*Fory)
+
+// WithCompatible sets the compatible mode for the Fory instance
+func WithCompatible(compatible bool) ForyOption {
+ return func(f *Fory) {
+ f.compatible = compatible
+ }
+}
+
+// WithReferenceTracking sets the reference tracking mode for the Fory instance
+func WithReferenceTracking(referenceTracking bool) ForyOption {
+ return func(f *Fory) {
+ f.referenceTracking = referenceTracking
+ }
+}
+
+// WithScopedMetaShare sets the scoped meta share mode for the Fory instance
+func WithScopedMetaShare(enabled bool) ForyOption {
+ return func(f *Fory) {
+ if f.metaContext == nil {
+ f.metaContext = NewMetaContext(enabled)
+ } else {
+ f.metaContext.SetScopedMetaShareEnabled(enabled)
+ }
+ }
+}
+
func NewFory(referenceTracking bool) *Fory {
+ return NewForyWithOptions(WithReferenceTracking(referenceTracking))
+}
+
+// NewForyWithOptions creates a Fory instance with configurable options
+func NewForyWithOptions(options ...ForyOption) *Fory {
fory := &Fory{
- refResolver: newRefResolver(referenceTracking),
- referenceTracking: referenceTracking,
+ refResolver: nil,
+ referenceTracking: false,
Review Comment:
Done. Is this change okay?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(go): Implement compatible mode with metashare mode [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2607:
URL: https://github.com/apache/fory/pull/2607#discussion_r2348218277
##########
go/fory/fory.go:
##########
@@ -44,19 +84,43 @@ func NewFory(referenceTracking bool) *Fory {
}
}
+ // Initialize meta context if compatible mode is enabled
+ if fory.compatible {
+ fory.metaContext = NewMetaContext(true)
+ }
+
+ fory.refResolver = newRefResolver(fory.refTracking)
return fory
}
// NewForyWithIsolatedTypes creates a Fory instance with isolated type resolver
// for use cases that need independent type registration
-func NewForyWithIsolatedTypes(referenceTracking bool) *Fory {
+func NewForyWithIsolatedTypes(refTracking bool) *Fory {
Review Comment:
@thisingl I'm a little confused, why do we need this API, this looks obscure to me.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(go): Implement compatible mode with metashare mode [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang merged PR #2607:
URL: https://github.com/apache/fory/pull/2607
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(go): Implement compatible mode with metashare mode [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2607:
URL: https://github.com/apache/fory/pull/2607#discussion_r2348160051
##########
go/fory/type_def_decoder.go:
##########
@@ -61,6 +62,7 @@ func decodeTypeDef(fory *Fory, buffer *ByteBuffer) (*TypeDef, error) {
// Read name or type ID according to the registerByName flag
var typeId TypeId
var nsBytes, nameBytes *MetaStringBytes
+ var typ reflect.Type
Review Comment:
use `type_`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(go): Implement compatible mode with metashare mode [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2607:
URL: https://github.com/apache/fory/pull/2607#discussion_r2347982543
##########
go/fory/fory.go:
##########
@@ -24,13 +24,53 @@ import (
"sync"
)
+// ForyOption represents a configuration option for Fory instances
+type ForyOption func(*Fory)
+
+// WithCompatible sets the compatible mode for the Fory instance
+func WithCompatible(compatible bool) ForyOption {
+ return func(f *Fory) {
+ f.compatible = compatible
+ }
+}
+
+// WithReferenceTracking sets the reference tracking mode for the Fory instance
+func WithReferenceTracking(referenceTracking bool) ForyOption {
+ return func(f *Fory) {
+ f.referenceTracking = referenceTracking
+ }
+}
+
+// WithScopedMetaShare sets the scoped meta share mode for the Fory instance
+func WithScopedMetaShare(enabled bool) ForyOption {
+ return func(f *Fory) {
+ if f.metaContext == nil {
+ f.metaContext = NewMetaContext(enabled)
+ } else {
+ f.metaContext.SetScopedMetaShareEnabled(enabled)
+ }
+ }
+}
+
func NewFory(referenceTracking bool) *Fory {
+ return NewForyWithOptions(WithReferenceTracking(referenceTracking))
+}
+
+// NewForyWithOptions creates a Fory instance with configurable options
+func NewForyWithOptions(options ...ForyOption) *Fory {
fory := &Fory{
- refResolver: newRefResolver(referenceTracking),
- referenceTracking: referenceTracking,
+ refResolver: nil,
+ referenceTracking: false,
Review Comment:
```suggestion
refTracking: false,
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(go): Implement compatible mode with metashare mode [fory]
Posted by "junjiexh (via GitHub)" <gi...@apache.org>.
junjiexh commented on code in PR #2607:
URL: https://github.com/apache/fory/pull/2607#discussion_r2348051124
##########
go/fory/fory_metashare_test.go:
##########
@@ -0,0 +1,181 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package fory
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+// Test structs for metashare testing
+
+type SimpleDataClass struct {
+ Name string `fory:"name"`
+ Age int32 `fory:"age"`
+ Active bool `fory:"active"`
+}
+type ExtendedDataClass struct {
+ Name string `fory:"name"`
+ Age int32 `fory:"age"`
+ Active bool `fory:"active"`
+ Email string `fory:"email"` // Additional field
+}
+
+type ReducedDataClass struct {
+ Name string `fory:"name"`
+ Age int32 `fory:"age"`
+ // Missing 'active' field
+}
+
+func TestMetaShareEnabled(t *testing.T) {
+ fory := NewForyWithOptions(WithCompatible(true))
+
+ assert.True(t, fory.compatible, "Expected compatible mode to be enabled")
+ assert.NotNil(t, fory.metaContext, "Expected metaContext to be initialized when compatible=true")
+ assert.True(t, fory.metaContext.IsScopedMetaShareEnabled(), "Expected scoped meta share to be enabled by default when compatible=true")
+}
+
+func TestMetaShareDisabled(t *testing.T) {
+ fory := NewForyWithOptions(WithCompatible(false))
+
+ assert.False(t, fory.compatible, "Expected compatible mode to be disabled")
+ assert.Nil(t, fory.metaContext, "Expected metaContext to be nil when compatible=false")
+}
+
+func TestSimpleDataClassSerialization(t *testing.T) {
+ fory := NewForyWithOptions(WithCompatible(true))
+
+ // Register the struct
+ err := fory.RegisterTagType("SimpleDataClass", SimpleDataClass{})
Review Comment:
> @junjiexh Let's create an issue for this and update the API call in future after the API has been updated
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(go): Implement compatible mode with metashare mode [fory]
Posted by "junjiexh (via GitHub)" <gi...@apache.org>.
junjiexh commented on code in PR #2607:
URL: https://github.com/apache/fory/pull/2607#discussion_r2348017570
##########
go/fory/fory_metashare_test.go:
##########
@@ -0,0 +1,181 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package fory
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+// Test structs for metashare testing
+
+type SimpleDataClass struct {
+ Name string `fory:"name"`
Review Comment:
Oh, sorry, we don't. This is generated by copilot, I'll make sure to double-check my work next time.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(go): Implement compatible mode with metashare mode [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2607:
URL: https://github.com/apache/fory/pull/2607#discussion_r2347984846
##########
go/fory/fory.go:
##########
@@ -24,13 +24,53 @@ import (
"sync"
)
+// ForyOption represents a configuration option for Fory instances
+type ForyOption func(*Fory)
+
+// WithCompatible sets the compatible mode for the Fory instance
+func WithCompatible(compatible bool) ForyOption {
+ return func(f *Fory) {
+ f.compatible = compatible
+ }
+}
+
+// WithReferenceTracking sets the reference tracking mode for the Fory instance
+func WithReferenceTracking(referenceTracking bool) ForyOption {
+ return func(f *Fory) {
+ f.referenceTracking = referenceTracking
+ }
+}
+
+// WithScopedMetaShare sets the scoped meta share mode for the Fory instance
+func WithScopedMetaShare(enabled bool) ForyOption {
+ return func(f *Fory) {
+ if f.metaContext == nil {
+ f.metaContext = NewMetaContext(enabled)
+ } else {
+ f.metaContext.SetScopedMetaShareEnabled(enabled)
+ }
+ }
+}
+
func NewFory(referenceTracking bool) *Fory {
+ return NewForyWithOptions(WithReferenceTracking(referenceTracking))
+}
+
+// NewForyWithOptions creates a Fory instance with configurable options
+func NewForyWithOptions(options ...ForyOption) *Fory {
fory := &Fory{
- refResolver: newRefResolver(referenceTracking),
- referenceTracking: referenceTracking,
+ refResolver: nil,
+ referenceTracking: false,
Review Comment:
Rename all `reference` to `ref`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org