jsonstream

package module
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2024 License: Apache-2.0 Imports: 0 Imported by: 0

README

LaunchDarkly Streaming JSON for Go

Circle CI Documentation

Overview

The go-jsonstream library implements a streaming approach to JSON encoding and decoding which is more efficient than the standard mechanism in encoding/json. Unlike encoding/json or other reflection-based frameworks, it has no knowledge of structs or other complex types; you must explicitly tell it what values and properties to write or read. It was implemented for the LaunchDarkly Go SDK and other LaunchDarkly Go components, but may be useful in other applications.

There are two possible implementations, selectable via build tags:

  1. A default implementation that has no external dependencies, compatible with all platforms. This performs better than encoding/json, but not as well as the other two below.

  2. An implementation that uses the low-level tokenizing and output functions from the easyjson library (but without the code generation mechanism that easyjson also provides). This is used if you enable the build tag launchdarkly_easyjson.

Although the easyjson implementation is the fastest, it is opt-in rather than being the default, for two reasons:

  • By default, easyjson uses Go's unsafe package, which may be undesirable or not allowed depending on your runtime environment. Easyjson disables the use of unsafe if you set the build tag easyjson_nounsafe or appengine.

  • Although easyjson is widely used, at this time it does not have a stable 1.x version.

The design of go-jsonstream allows encoding/decoding logic to be written against the same API without needing to know whether the easyjson implementation will be used at build time or not. There is an adapter (also conditionally compiled with the launchdarkly_easyjson tag) to allow go-jsonstream to plug directly into a jlexer.Lexer or jwriter.Writer that is being used to read or write some other type with easyjson.

The unit tests for go-jsonstream define a common test suite that is run against the default implementation and the easyjson implementation, to verify that their behavior is consistent across a large number of permutations of possible JSON inputs and outputs.

Supported Go versions

This version of the project requires a Go version of 1.18 or higher.

Contributing

We encourage pull requests and other contributions from the community. Check out our contributing guidelines for instructions on how to contribute to this SDK.

About LaunchDarkly

  • LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:
    • Roll out a new feature to a subset of your users (like a group of users who opt-in to a beta tester group), gathering feedback and bug reports from real-world use cases.
    • Gradually roll out a feature to an increasing percentage of users, and track the effect that the feature has on key metrics (for instance, how likely is a user to complete a purchase if they have feature A versus feature B?).
    • Turn off a feature that you realize is causing performance problems in production, without needing to re-deploy, or even restart the application with a changed configuration file.
    • Grant access to certain features based on user attributes, like payment plan (eg: users on the ‘gold’ plan get access to more features than users in the ‘silver’ plan). Disable parts of your application to facilitate maintenance, without taking everything offline.
  • LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Check out our documentation for a complete list.
  • Explore LaunchDarkly

Documentation

Overview

Package jsonstream provides a fast streaming JSON encoding and decoding mechanism.

The base package is empty; see the jreader and jwriter subpackages.

In the default implementation, these packages have no external dependencies. Setting the build tag "launchdarkly_easyjson" causes them to use https://github.com/mailru/easyjson as the underlying reader/writer implementation.

For more information, see: https://github.com/launchdarkly/go-jsonstream

Directories

Path Synopsis
internal
commontest
Package commontest provides test logic for JSON reading and writing.
Package commontest provides test logic for JSON reading and writing.
Package jreader provides an efficient mechanism for reading JSON data sequentially.
Package jreader provides an efficient mechanism for reading JSON data sequentially.
Package jwriter provides an efficient mechanism for writing JSON data sequentially.
Package jwriter provides an efficient mechanism for writing JSON data sequentially.

Jump to

Keyboard shortcuts

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