Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Variables

LOGICAL_TYPE

LOGICAL_TYPE: any = null

NAME_PATTERN

NAME_PATTERN: RegExp = /^[A-Za-z_][A-Za-z0-9_]*$/

RANDOM

RANDOM: Lcg = new utils.Lcg()

TAP

TAP: any = new Tap(new buffer.SlowBuffer(1024))

Tap

Tap: Tap = utils.Tap

UNDERLYING_TYPES

UNDERLYING_TYPES: any[] = []

buffer

buffer: "buffer" = require('buffer')

This module defines all Avro data types and their serialization logic.

debug

debug: function = util.debuglog('avsc:types')

Type declaration

    • (msg: string, ...param: any[]): void
    • Parameters

      • msg: string
      • Rest ...param: any[]

      Returns void

f

f: format = util.format

util

util: "util" = require('util')

This module defines all Avro data types and their serialization logic.

utils

utils: object = require('./avro-utils')

This module defines all Avro data types and their serialization logic.

Type declaration

Functions

AbstractLongType

  • AbstractLongType(noUnpack: any): void
  • Customizable long.

    This allows support of arbitrarily large long (e.g. larger than Number.MAX_SAFE_INTEGER). See LongType.__with method above. Note that we can't use a logical type because we need a "lower-level" hook here: passing through through the standard long would cause a loss of precision.

    Parameters

    • noUnpack: any

    Returns void

ArrayType

  • ArrayType(schema: any, opts: any): void

BooleanType

  • BooleanType(): void

BytesType

  • BytesType(): void
  • Bytes.

    These are represented in memory as Buffers rather than binary-encoded strings. This is more efficient (when decoding/encoding from bytes, the common use-case), idiomatic, and convenient.

    Note the coercion in _copy.

    Returns void

DoubleType

  • DoubleType(): void

EnumType

  • EnumType(schema: any, opts: any): void
  • Avro enum type.

    Represented as strings (with allowed values from the set of symbols). Using integers would be a reasonable option, but the performance boost is arguably offset by the legibility cost and the extra deviation from the JSON encoding convention.

    An integer representation can still be used (e.g. for compatibility with TypeScript enums) by overriding the EnumType with a LongType (e.g. via parse's registry).

    Parameters

    • schema: any
    • opts: any

    Returns void

Field

  • Field(schema: any, opts: any): void

FixedType

  • FixedType(schema: any, opts: any): void

FloatType

  • FloatType(): void

Hash

  • Hash(): void

IntType

  • IntType(): void

LogicalType

  • LogicalType(schema: any, opts: any): void

LongType

  • LongType(): void
  • Longs.

    We can't capture all the range unfortunately since JavaScript represents all numbers internally as doubles, so the default implementation plays safe and throws rather than potentially silently change the data. See __with or AbstractLongType below for a way to implement a custom long type.

    Returns void

MapType

  • MapType(schema: any, opts: any): void

NullType

  • NullType(): void

PrimitiveType

  • PrimitiveType(noFreeze: any): void
  • Base primitive Avro type.

    Most of the primitive types share the same cloning and resolution mechanisms, provided by this class. This class also lets us conveniently check whether a type is a primitive using instanceof.

    Parameters

    • noFreeze: any

    Returns void

RecordType

  • RecordType(schema: any, opts: any): void
  • Avro record.

    Values are represented as instances of a programmatically generated constructor (similar to a "specific record"), available via the getRecordConstructor method. This "specific record class" gives significant speedups over using generics objects.

    Note that vanilla objects are still accepted as valid as long as their fields match (this makes it much more convenient to do simple things like update nested records).

    This type is also used for errors (similar, except for the extra Error constructor call) and for messages (see comment below).

    Parameters

    • schema: any
    • opts: any

    Returns void

Resolver

  • Resolver(readerType: Type): void

StringType

  • StringType(): void

Type

  • Type(schema: any, opts: any): void
  • "Abstract" base Avro type.

    This class' constructor will register any named types to support recursive schemas. All type values are represented in memory similarly to their JSON representation, except for:

    • bytes and fixed which are represented as Buffers.
    • unions which will be "unwrapped" unless the wrapUnions option is set.

      See individual subclasses for details.

    Parameters

    • schema: any
    • opts: any

    Returns void

UnionType

  • UnionType(schema: any, opts: any): void

UnwrappedUnionType

  • UnwrappedUnionType(schema: any, opts: any): void
  • "Natural" union type.

    This representation doesn't require a wrapping object and is therefore simpler and generally closer to what users expect. However it cannot be used to represent all Avro unions since some lead to ambiguities (e.g. if two number types are in the union).

    Currently, this union supports at most one type in each of the categories below:

    • null
    • boolean
    • int, long, float, double
    • string, enum
    • bytes, fixed
    • array
    • map, record

    Parameters

    • schema: any
    • opts: any

    Returns void

WrappedUnionType

  • WrappedUnionType(schema: any, opts: any): void
  • Compatible union type.

    Values of this type are represented in memory similarly to their JSON representation (i.e. inside an object with single key the name of the contained type).

    This is not ideal, but is the most efficient way to unambiguously support all unions. Here are a few reasons why the wrapping object is necessary:

    • Unions with multiple number types would have undefined behavior, unless numbers are wrapped (either everywhere, leading to large performance and convenience costs; or only when necessary inside unions, making it hard to understand when numbers are wrapped or not).
    • Fixed types would have to be wrapped to be distinguished from bytes.
    • Using record's constructor names would work (after a slight change to use the fully qualified name), but would mean that generic objects could no longer be valid records (making it inconvenient to do simple things like creating new records).

    Parameters

    • schema: any
    • opts: any

    Returns void

combineBuffers

  • combineBuffers(types: any, opts: any): any
  • Combine bytes and fixed.

    This function is optimized to avoid creating new types when possible: in case of a size mismatch between fixed types, it will continue looking through the array to find an existing bytes type (rather than exit early by creating one eagerly).

    Parameters

    • types: any
    • opts: any

    Returns any

combineNumbers

  • combineNumbers(types: any): any
  • Combine number types.

    Note that never have to create a new type here, we are guaranteed to be able to reuse one of the input types as super-type.

    Parameters

    • types: any

    Returns any

combineObjects

  • combineObjects(types: any, opts: any): any
  • Combine maps and records.

    Field defaults are kept when possible (i.e. when no coercion to a map happens), with later definitions overriding previous ones.

    Parameters

    • types: any
    • opts: any

    Returns any

combineStrings

  • combineStrings(types: any, opts: any): any
  • Combine enums and strings.

    The order of the returned symbols is undefined and the returned enum is

    Parameters

    • types: any
    • opts: any

    Returns any

getAliases

  • getAliases(obj: any): string[]
  • Get all aliases for a type (including its name).

    Parameters

    • obj: any

      Typically a type or a field. Its aliases property must exist and be an array.

    Returns string[]

getClassName

  • getClassName(typeName: string): string
  • Return a type's class name from its Avro type name.

    We can't simply use constructor.name since it isn't supported in all browsers.

    Parameters

    • typeName: string

      Type name.

    Returns string

getTypeBucket

  • getTypeBucket(type: Type): any

getValueBucket

  • getValueBucket(val: any[]): "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function" | "buffer" | "null" | "array"
  • Infer a value's bucket (see unwrapped unions for more details).

    Parameters

    • val: any[]

      Any value.

    Returns "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function" | "buffer" | "null" | "array"

isAmbiguous

  • isAmbiguous(types: any[]): boolean
  • Check whether a collection of types leads to an ambiguous union.

    Parameters

    • types: any[]

      Array of types.

    Returns boolean

isJsonBuffer

  • isJsonBuffer(obj: any): boolean

isPrimitive

  • isPrimitive(typeName: any): boolean

isSafeLong

  • isSafeLong(n: number): boolean
  • Check whether a long can be represented without precision loss.

    Parameters

    • n: number

      The number.

      Two things to note:

      • We are not using the Number constants for compatibility with older browsers.
      • We must remove one from each bound because of rounding errors.

    Returns boolean

isValidName

  • isValidName(str: any): boolean

qualify

  • qualify(name: string, namespace: string): string
  • Verify and return fully qualified name.

    Parameters

    • name: string

      Full or short name. It can be prefixed with a dot to force global namespace.

    • namespace: string

      Optional namespace.

    Returns string

readArraySize

  • readArraySize(tap: Tap): number
  • Get the number of elements in an array block.

    Parameters

    • tap: Tap

      A tap positioned at the beginning of an array block.

    Returns number

readValue

  • Read a value from a tap.

    Parameters

    • type: Type

      The type to decode.

    • tap: Tap

      The tap to read from. No checks are performed here.

    • resolver: Resolver

      Optional resolver. It must match the input type.

    • lazy: boolean

      Skip trailing fields when using a resolver.

    Returns any

throwInvalidError

  • throwInvalidError(val: any[], type: Type): void
  • Throw a somewhat helpful error on invalid object.

    Parameters

    • val: any[]

      The object to reject.

    • type: Type

      The type to check against.

      This method is mostly used from _write to signal an invalid object for a given type. Note that this provides less information than calling isValid with a hook since the path is not propagated (for efficiency reasons).

    Returns void

unqualify

  • unqualify(name: string): string

Object literals

TYPES

TYPES: object

array

array: ArrayType = ArrayType

boolean

boolean: BooleanType = BooleanType

bytes

bytes: BytesType = BytesType

double

double: DoubleType = DoubleType

enum

enum: EnumType = EnumType

error

error: RecordType = RecordType

fixed

fixed: FixedType = FixedType

float

float: FloatType = FloatType

int

int: IntType = IntType

long

long: LongType = LongType

map

map: MapType = MapType

null

null: NullType = NullType

record

record: RecordType = RecordType

string

string: StringType = StringType

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc