Unit Grijjy.Bson.IO

DescriptionUsesClasses, Interfaces, Objects and RecordsFunctions and ProceduresTypesConstantsVariables

Description

JSON and BSON reading and writing.

Quick Start

Consider this JSON document:

    { "x" : 1,
      "y" : 2,
      "z" : [ 3.14, true] }
  

You can serialize it manually to BSON like this:

  var
    Writer: IgoBsonWriter;
    Bson: TBytes;
  begin
    Writer := TgoBsonWriter.Create;
    Writer.WriteStartDocument;

    Writer.WriteName('x');
    Writer.WriteInt32(1);

    Writer.WriteInt32('y', 2); // Writes name and value in single call

    Writer.WriteName('z');
    Writer.WriteStartArray;
    Writer.WriteDouble(3.14);
    Writer.WriteBoolean(True);
    Writer.WriteEndArray;

    Writer.WriteEndDocument;

    Bson := Writer.ToBson;
  end;

Likewise, you can serialize to JSON by using the IgoJsonWriter interface instead.

You can also manually deserialize by using the IgoBsonReader and IgoJsonReader interfaces. However, these are a bit more complicated to use since you don't know the deserialized BSON types in advance.

You can look at the unit tests in the unit Grijjy.Data.Bson.IO.Tests for examples of manual serialization and deserialization.

Overview

Classes, Interfaces, Objects and Records

Name Description
Class EgoJsonParserError Type of exception that is raised when parsing an invalid JSON source.
Interface IgoBsonBaseWriter Base interface for IgoBsonWriter, IgoJsonWriter and IgoBsonDocumentWriter
Interface IgoBsonWriter Interface for writing BSON values to binary BSON format.
Interface IgoJsonWriter Interface for writing BSON values to JSON format.
Interface IgoBsonDocumentWriter Interface for writing BSON values to a BSON document.
Interface IgoBsonReaderBookmark A bookmark that can be used to return a reader to the current position and state.
Interface IgoBsonBaseReader Base interface for IgoBsonReader, IgoJsonReader and IgoBsonDocumentReader
Interface IgoBsonReader Interface for reading BSON values from binary BSON format.
Interface IgoJsonReader Interface for reading BSON values from JSON format.
Interface IgoBsonDocumentReader Interface for reading BSON values from a BSON Document.
Class TgoBsonBaseWriter Abstract base class of TgoBsonWriter and TgoJsonWriter.
Class TgoBsonWriter Stock implementation of the IgoBsonWriter interface.
Class TgoJsonWriter Stock implementation of the IgoJsonWriter interface.
Class TgoBsonDocumentWriter Stock implementation of the IgoBsonDocumentWriter interface.
Class TgoBsonBaseReader Abstract base class of TgoBsonReader and TgoJsonReader.
Class TgoBsonReader Stock implementation of the IgoBsonReader interface.
Class TgoJsonReader Stock implementation of the IgoJsonReader interface.
Class TgoBsonDocumentReader Stock implementation of the IgoBsonDocumentReader interface.

Types

TgoBsonWriterState = (...);
TgoBsonReaderState = (...);
TgoBsonContextType = (...);

Constants

RS_BSON_NOT_SUPPORTED = 'Unsupported feature';
RS_BSON_INVALID_WRITER_STATE = 'Cannot write Bson/Json element in current state';
RS_BSON_INVALID_READER_STATE = 'Cannot read Bson/Json element in current state';
RS_BSON_INVALID_DATA = 'Bson/Json data is invalid';
RS_BSON_INT_EXPECTED = 'Integer value expected';
RS_BSON_UNEXPECTED_TOKEN = 'Unexpected token';
RS_BSON_TOKEN_EXPECTED = 'Expected token with value "%s" but got "%s"';
RS_BSON_STRING_EXPECTED = 'String value expected';
RS_BSON_STRING_WITH_VALUE_EXPECTED = 'Expected string with value "%s" but got "%s"';
RS_BSON_INT_OR_STRING_EXPECTED = 'Integer or string value expected';
RS_BSON_COLON_EXPECTED = 'Colon (":") expected';
RS_BSON_COMMA_EXPECTED = 'Comma (",") expected';
RS_BSON_QUOTE_EXPECTED = 'Double quotes (") expected';
RS_BSON_CLOSE_BRACKET_EXPECTED = 'Close bracket ("]") expected';
RS_BSON_CLOSE_BRACE_EXPECTED = 'Curly close brace ("}") expected';
RS_BSON_COMMA_OR_CLOSE_BRACE_EXPECTED = 'Comma (",") or curly close brace ("}") expected';
RS_BSON_STRING_OR_CLOSE_BRACE_EXPECTED = 'String or curly close brace ("}") expected';
RS_BSON_INVALID_NUMBER = 'Invalid number';
RS_BSON_INVALID_STRING = 'Invalid character string';
RS_BSON_INVALID_DATE = 'Invalid date value';
RS_BSON_INVALID_GUID = 'Invalid GUID value';
RS_BSON_INVALID_NEW_STATEMENT = 'Invalid "new" statement';
RS_BSON_INVALID_EXTENDED_JSON = 'Invalid extended JSON';
RS_BSON_INVALID_BINARY_TYPE = 'Invalid binary type';
RS_BSON_INVALID_REGEX = 'Invalid regular expression';
RS_BSON_INVALID_UNICODE_CODEPOINT = 'Invalid Unicode codepoint';
RS_BSON_JS_DATETIME_STRING_NOT_SUPPORTED = 'JavaScript date/time strings are not supported';

Description

Types

TgoBsonWriterState = (...);

State of a IgoBsonBaseWriter

Values
  • Initial: Initial state
  • Name: The writer is positioned to write a name
  • Value: The writer is positioned to write a value
  • ScopeDocument: The writer is positioned to write a scope document (call WriteStartDocument to start writing the scope document).
  • Done: The writer is done
  • Closed: The writer is closed
TgoBsonReaderState = (...);

State of a IgoBsonBaseReader

Values
  • Initial: Initial state
  • Type: The reader is positioned at the type of an element or value
  • Name: The reader is positioned at the name of an element
  • Value: The reader is positioned at the value
  • ScopeDocument: The reader is positioned at a scope document
  • EndOfDocument: The reader is positioned at the end of a document
  • EndOfArray: The reader is positioned at the end of an array
  • Done: The reader has finished reading a document
  • Closed: The reader is closed
TgoBsonContextType = (...);

Used internally by BSON/JSON readers and writers to represent the current context.

Values
  • TopLevel: The top level of a BSON document
  • Document: A (possible embedded) BSON document
  • Array: A BSON array
  • JavaScriptWithScope: A JavaScript w/Scope BSON value
  • ScopeDocument: The scope document of a JavaScript w/Scope BSON value

Constants

RS_BSON_NOT_SUPPORTED = 'Unsupported feature';
 
RS_BSON_INVALID_WRITER_STATE = 'Cannot write Bson/Json element in current state';
 
RS_BSON_INVALID_READER_STATE = 'Cannot read Bson/Json element in current state';
 
RS_BSON_INVALID_DATA = 'Bson/Json data is invalid';
 
RS_BSON_INT_EXPECTED = 'Integer value expected';
 
RS_BSON_UNEXPECTED_TOKEN = 'Unexpected token';
 
RS_BSON_TOKEN_EXPECTED = 'Expected token with value "%s" but got "%s"';
 
RS_BSON_STRING_EXPECTED = 'String value expected';
 
RS_BSON_STRING_WITH_VALUE_EXPECTED = 'Expected string with value "%s" but got "%s"';
 
RS_BSON_INT_OR_STRING_EXPECTED = 'Integer or string value expected';
 
RS_BSON_COLON_EXPECTED = 'Colon (":") expected';
 
RS_BSON_COMMA_EXPECTED = 'Comma (",") expected';
 
RS_BSON_QUOTE_EXPECTED = 'Double quotes (") expected';
 
RS_BSON_CLOSE_BRACKET_EXPECTED = 'Close bracket ("]") expected';
 
RS_BSON_CLOSE_BRACE_EXPECTED = 'Curly close brace ("}") expected';
 
RS_BSON_COMMA_OR_CLOSE_BRACE_EXPECTED = 'Comma (",") or curly close brace ("}") expected';
 
RS_BSON_STRING_OR_CLOSE_BRACE_EXPECTED = 'String or curly close brace ("}") expected';
 
RS_BSON_INVALID_NUMBER = 'Invalid number';
 
RS_BSON_INVALID_STRING = 'Invalid character string';
 
RS_BSON_INVALID_DATE = 'Invalid date value';
 
RS_BSON_INVALID_GUID = 'Invalid GUID value';
 
RS_BSON_INVALID_NEW_STATEMENT = 'Invalid "new" statement';
 
RS_BSON_INVALID_EXTENDED_JSON = 'Invalid extended JSON';
 
RS_BSON_INVALID_BINARY_TYPE = 'Invalid binary type';
 
RS_BSON_INVALID_REGEX = 'Invalid regular expression';
 
RS_BSON_INVALID_UNICODE_CODEPOINT = 'Invalid Unicode codepoint';
 
RS_BSON_JS_DATETIME_STRING_NOT_SUPPORTED = 'JavaScript date/time strings are not supported';
 

Generated by P2PasDoc 0.13.0 on 2017-04-25 12:54:26