conv

package
v0.2.2-dep3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 1 Imported by: 3

README

conv

import "github.com/cloudwego/dynamicgo/conv"

Index

Variables

var (
    // CtxKeyHTTPResponse is the key for http.ResponseSetter in context
    CtxKeyHTTPResponse = &ContextKey{}
    // CtxKeyHTTPRequest is the key for http.RequestGetter in context
    CtxKeyHTTPRequest = &ContextKey{}
    // CtxKeyThriftRespBase is the key for base.Base in context
    CtxKeyThriftRespBase = &ContextKey{}
    // CtxKeyThriftReqBase is the key for base.BaseResp in context
    CtxKeyThriftReqBase = &ContextKey{}
    // CtxKeyConvOptions is the key for Options in context
    CtxKeyConvOptions = &ContextKey{}
)
var (
    // DefaultBufferSize is the default buffer size for conversion
    DefaultBufferSize = 4096
    // DefaultHttpValueBufferSize is the default buffer size for copying a json value
    DefaulHttpValueBufferSizeForJSON = 1024
    // DefaultHttpValueBufferSize is the default buffer size for copying a http value
    DefaulHttpValueBufferSizeForScalar = 64
)

func FreeBytes

func FreeBytes(b *[]byte)

FreeBytes returns a byte slice to pool and reset it

func NewBytes

func NewBytes() *[]byte

NewBytes returns a new byte slice from pool

type ContextKey

ContextKey is the key type for context arguments

type ContextKey struct {
    // contains filtered or unexported fields
}

type Options

type Options struct {
    // DisallowUnknownField indicates if unknown fields should be skipped
    DisallowUnknownField bool
    // WriteDefaultField indicates if default-requireness fields should be written if
    WriteDefaultField bool
    // EnableValueMapping indicates if value mapping (api.js_conv...) should be enabled
    EnableValueMapping bool
    // EnableHttpMapping indicates if http mapping (api.query|api.header...) should be enabled
    EnableHttpMapping bool
    // HttpMappingAsExtra indicates if continuing convert the same field after http mapping
    HttpMappingAsExtra bool
    // EnableThriftBase indicates if thrift/base should be recoginized and mapping to/from context
    EnableThriftBase bool
    // UseNativeSkip indicates if use thrift.SkipNative() or thrift.SkipGo()
    UseNativeSkip bool
    // Int64AsString indicates if string value cane be read as **Int8/Int16/Int32/Int64/Float64**,
    // or in response a **Int64** value can be written as string
    String2Int64 bool
    // WriteRequireField indicates if required-requireness fields should be written empty value if
    // not found
    WriteRequireField bool
    // NoBase64Binary indicates if base64 string shoud be Encode/Decode as []byte
    NoBase64Binary bool
    // ByteAsUint8 indicates if byte should be conv as uint8 (default is int8), this only works for t2j now
    ByteAsUint8 bool
    // WriteOptionalField indicates if optional-requireness fields should be written when not given
    WriteOptionalField bool
    // TracebackRequredOrRootFields indicates if required-requireness
    // or root-level fields should be seeking on http-values when reading failed from current layer of json.
    // this option is only used in j2t now.
    TracebackRequredOrRootFields bool
    // NoCopyString indicates if string should be copied or just referenced (if possible)
    NoCopyString bool
}

Generated by gomarkdoc

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// CtxKeyHTTPResponse is the key for http.ResponseSetter in context
	CtxKeyHTTPResponse = &ContextKey{}
	// CtxKeyHTTPRequest is the key for http.RequestGetter in context
	CtxKeyHTTPRequest = &ContextKey{}
	// CtxKeyThriftRespBase is the key for base.Base in context
	CtxKeyThriftRespBase = &ContextKey{}
	// CtxKeyThriftReqBase is the key for base.BaseResp in context
	CtxKeyThriftReqBase = &ContextKey{}
	// CtxKeyConvOptions is the key for Options in context
	CtxKeyConvOptions = &ContextKey{}
)
View Source
var (
	// DefaultBufferSize is the default buffer size for conversion
	DefaultBufferSize = 4096
	// DefaultHttpValueBufferSize is the default buffer size for copying a json value
	DefaulHttpValueBufferSizeForJSON = 1024
	// DefaultHttpValueBufferSize is the default buffer size for copying a http value
	DefaulHttpValueBufferSizeForScalar = 64
)

Functions

func FreeBytes

func FreeBytes(b *[]byte)

FreeBytes returns a byte slice to pool and reset it

func NewBytes

func NewBytes() *[]byte

NewBytes returns a new byte slice from pool

Types

type ContextKey

type ContextKey struct {
	// contains filtered or unexported fields
}

ContextKey is the key type for context arguments

type Options

type Options struct {

	// EnableValueMapping indicates if value mapping (api.js_conv...) should be enabled
	EnableValueMapping bool
	// EnableHttpMapping indicates if http mapping (api.query|api.header...) should be enabled
	EnableHttpMapping bool
	// EnableThriftBase indicates if thrift/base should be recognized and mapping to/from context
	EnableThriftBase bool

	// String2Int64 indicates if string value cane be read as **Int8/Int16/Int32/Int64/Float64**,
	String2Int64 bool

	// Int642Stringin indicates if a int64 value a **Int64** value can be written as string
	Int642String bool

	// NoBase64Binary indicates if base64 string should be Encode/Decode as []byte
	NoBase64Binary bool
	// ByteAsUint8 indicates if byte should be conv as uint8 (default is int8), this only works for t2j now
	ByteAsUint8 bool

	// WriteOptionalField indicates if optional-requireness fields should be written when not given
	WriteOptionalField bool
	// WriteDefaultField indicates if default-requireness fields should be written if
	WriteDefaultField bool
	// WriteRequireField indicates if required-requireness fields should be written empty value if
	// not found
	WriteRequireField bool
	// DisallowUnknownField indicates if unknown fields should be skipped
	DisallowUnknownField bool

	// ReadHttpValueFallback indicates if http-annotated fields should fallback to http body after reading from non-body parts (header,cookie...) failed
	ReadHttpValueFallback bool
	// WriteHttpValueFallback indicates if http-annotated fields should fallback to http body after writing to non-body parts (header,cookie...) failed
	WriteHttpValueFallback bool
	// TracebackRequredOrRootFields indicates if required-requireness
	// or root-level fields should be seeking on http-values when reading failed from current layer of json.
	// this option is only used in j2t now.
	TracebackRequredOrRootFields bool
	// OmitHttpMappingErrors indicates to omit http-mapping failing errors.
	// If there are more-than-one HTTP annotations on the field, dynamicgo will try to mapping next annotation source (from left to right) until succeed.
	OmitHttpMappingErrors bool

	// NoCopyString indicates if string-kind http values should be copied or just referenced (if possible)
	NoCopyString bool
	// UseNativeSkip indicates if using thrift.SkipNative() or thrift.SkipGo()
	UseNativeSkip bool

	// ConvertException indicates that it returns error for thrift exception fields when doing BinaryConv t2j
	ConvertException bool

	// UseKitexHttpEncoding indicating using kitex's text encoding to output complex http values
	UseKitexHttpEncoding bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL