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

Method Encode

go/fory/meta/meta_string_encoder.go:38–50  ·  view source on GitHub ↗

Encode the input string to MetaString using adaptive encoding

(input string)

Source from the content-addressed store, hash-verified

36
37// Encode the input string to MetaString using adaptive encoding
38func (e *Encoder) Encode(input string) (MetaString, error) {
39 if !isASCII(input) {
40 return MetaString{
41 inputString: input,
42 encoding: UTF_8,
43 specialChar1: e.specialChar1,
44 specialChar2: e.specialChar2,
45 encodedBytes: []byte(input),
46 }, nil
47 }
48 encoding := e.ComputeEncoding(input)
49 return e.EncodeWithEncoding(input, encoding)
50}
51
52// EncodeWithEncoding Encodes the input string to MetaString using specified encoding.
53func (e *Encoder) EncodeWithEncoding(input string, encoding Encoding) (MetaString, error) {

Callers 4

TestMetaStringResolverFunction · 0.95
TestAsciiEncodingFunction · 0.95
TestNonAsciiEncodingFunction · 0.95

Calls 3

ComputeEncodingMethod · 0.95
EncodeWithEncodingMethod · 0.95
isASCIIFunction · 0.85

Tested by 4

TestMetaStringResolverFunction · 0.76
TestAsciiEncodingFunction · 0.76
TestNonAsciiEncodingFunction · 0.76