MCPcopy Create free account
hub / github.com/apache/fory / New

Function New

go/fory/fory.go:189–230  ·  view source on GitHub ↗

New creates a new Fory instance with the given options

(opts ...Option)

Source from the content-addressed store, hash-verified

187
188// New creates a new Fory instance with the given options
189func New(opts ...Option) *Fory {
190 f := &Fory{
191 config: defaultConfig(),
192 }
193
194 // Apply options
195 for _, opt := range opts {
196 opt(f)
197 }
198 f.applyCompatibleDefault()
199
200 // Initialize meta context if compatible mode is enabled
201 if f.config.Compatible {
202 f.metaContext = &MetaContext{
203 typeMap: make(map[uintptr]uint32),
204 readTypeInfos: make([]*TypeInfo, 0),
205 scopedMetaShareEnable: true,
206 }
207 }
208
209 // Initialize resolvers
210 f.typeResolver = newTypeResolver(f)
211 f.refResolver = newRefResolver(f.config.TrackRef)
212
213 // Initialize reusable contexts with resolvers
214 f.writeCtx = NewWriteContext(f.config.TrackRef, f.config.MaxDepth)
215 f.writeCtx.typeResolver = f.typeResolver
216 f.writeCtx.refResolver = f.refResolver
217 f.writeCtx.compatible = f.config.Compatible
218 f.writeCtx.xlang = f.config.IsXlang
219
220 f.readCtx = NewReadContext(f.config.TrackRef)
221 f.readCtx.typeResolver = f.typeResolver
222 f.readCtx.refResolver = f.refResolver
223 f.readCtx.compatible = f.config.Compatible
224 f.readCtx.xlang = f.config.IsXlang
225 if f.config.IsXlang {
226 f.readCtx.rootHeader = XLangFlag
227 }
228
229 return f
230}
231
232func (f *Fory) applyCompatibleDefault() {
233 if !f.compatibleSet {

Calls 6

defaultConfigFunction · 0.85
newTypeResolverFunction · 0.85
newRefResolverFunction · 0.85
NewWriteContextFunction · 0.85
NewReadContextFunction · 0.85