...

Source file src/github.com/launchdarkly/go-jsonstream/v3/jreader/package_info.go

Documentation: github.com/launchdarkly/go-jsonstream/v3/jreader

     1  // Package jreader provides an efficient mechanism for reading JSON data sequentially.
     2  //
     3  // The high-level API for this package, Writer, is designed to facilitate writing custom JSON
     4  // marshaling logic concisely and reliably. Output is buffered in memory.
     5  //
     6  //	import (
     7  //	    "gopkg.in/launchdarkly/jsonstream.v1/jreader"
     8  //	)
     9  //
    10  //	type myStruct struct {
    11  //	    value int
    12  //	}
    13  //
    14  //	func (s *myStruct) ReadFromJSONReader(r *jreader.Reader) {
    15  //	    // reading a JSON object structure like {"value":2}
    16  //	    for obj := r.Object(); obj.Next; {
    17  //	        if string(obj.Name()) == "value" {
    18  //	            s.value = r.Int()
    19  //	        }
    20  //	    }
    21  //	}
    22  //
    23  //	func ParseMyStructJSON() {
    24  //	    var s myStruct
    25  //	    r := jreader.NewReader([]byte(`{"value":2}`))
    26  //	    s.ReadFromJSONReader(&r)
    27  //	    fmt.Printf("%+v\n", s)
    28  //	}
    29  //
    30  // The underlying low-level token parsing mechanism has two available implementations. The default
    31  // implementation has no external dependencies. For interoperability with the easyjson library
    32  // (https://github.com/mailru/easyjson), there is also an implementation that delegates to the
    33  // easyjson streaming parser; this is enabled by setting the build tag "launchdarkly_easyjson".
    34  // Be aware that by default, easyjson uses Go's "unsafe" package (https://pkg.go.dev/unsafe),
    35  // which may not be available on all platforms.
    36  //
    37  // Setting the "launchdarkly_easyjson" tag also adds a new constructor function,
    38  // NewReaderFromEasyJSONLexer, allowing Reader-based code to read directly from an existing
    39  // EasyJSON jlexer.Lexer. This may be desirable in order to define common unmarshaling logic that
    40  // may be used with or without EasyJSON. For example:
    41  //
    42  //	import (
    43  //	    "github.com/mailru/easyjson/jlexer"
    44  //	)
    45  //
    46  //	func (s *myStruct) UnmarshalEasyJSON(lexer *jlexer.Lexer) {
    47  //	    r := jreader.NewReaderFromEasyJSONLexer(lexer)
    48  //	    s.ReadFromJSONReader(&r)
    49  //	}
    50  package jreader
    51  

View as plain text