record TgoBsonValue

DescriptionHierarchyInternal Classes and RecordsFieldsMethodsProperties

Unit

Declaration

type TgoBsonValue = record

Description

The base "class" for all BSON values. It is implemented as a record type which can hold any type of BSON value.

Overview

Internal Classes and Records

_IValue = interface(IInterface)

Methods

class function Parse(const AJson: String): TgoBsonValue; static;
class function TryParse(const AJson: String; out AValue: TgoBsonValue): Boolean; static;
class function Load(const ABson: TBytes): TgoBsonValue; static;
class function TryLoad(const ABson: TBytes; out AValue: TgoBsonValue): Boolean; static;
class function LoadFromJsonFile(const AFilename: String): TgoBsonValue; static;
class function LoadFromJsonStream(const AStream: TStream): TgoBsonValue; static;
class function LoadFromBsonFile(const AFilename: String): TgoBsonValue; static;
class function LoadFromBsonStream(const AStream: TStream): TgoBsonValue; static;
procedure SaveToJsonFile(const AFilename: String); overload;
procedure SaveToJsonFile(const AFilename: String; const ASettings: TgoJsonWriterSettings); overload;
procedure SaveToJsonStream(const AStream: TStream); overload;
procedure SaveToJsonStream(const AStream: TStream; const ASettings: TgoJsonWriterSettings); overload;
procedure SaveToBsonFile(const AFilename: String);
procedure SaveToBsonStream(const AStream: TStream);
class operator Implicit(const A: Boolean): TgoBsonValue; static;
class operator Implicit(const A: Integer): TgoBsonValue; static;
class operator Implicit(const A: Int64): TgoBsonValue; static;
class operator Implicit(const A: Double): TgoBsonValue; static;
class operator Implicit(const A: Extended): TgoBsonValue; static;
class operator Implicit(const A: TDateTime): TgoBsonValue; static;
class operator Implicit(const A: String): TgoBsonValue; static;
class operator Implicit(const A: TBytes): TgoBsonValue; static;
class operator Implicit(const A: TGUID): TgoBsonValue; static;
class operator Implicit(const A: TgoObjectId): TgoBsonValue; static;
class operator Implicit(const A: TgoBsonValue): Boolean; static;
class operator Implicit(const A: TgoBsonValue): Integer; static;
class operator Implicit(const A: TgoBsonValue): Int64; static;
class operator Implicit(const A: TgoBsonValue): UInt64; static;
class operator Implicit(const A: TgoBsonValue): Double; static;
class operator Implicit(const A: TgoBsonValue): Extended; static;
class operator Implicit(const A: TgoBsonValue): TDateTime; static;
class operator Implicit(const A: TgoBsonValue): String; static;
class operator Implicit(const A: TgoBsonValue): TBytes; static;
class operator Implicit(const A: TgoBsonValue): TGUID; static;
class operator Implicit(const A: TgoBsonValue): TgoObjectId; static;
function ToLocalTime: TDateTime; inline;
function ToUniversalTime: TDateTime; inline;
class operator Equal(const A, B: TgoBsonValue): Boolean; static;
class operator NotEqual(const A, B: TgoBsonValue): Boolean; static;
function IsNil: Boolean; inline;
procedure SetNil; inline;
function ToBoolean(const ADefault: Boolean = False): Boolean; inline;
function ToInteger(const ADefault: Integer = 0): Integer; inline;
function ToInt64(const ADefault: Int64 = 0): Int64; inline;
function ToDouble(const ADefault: Double = 0): Double; inline;
function ToString(const ADefault: String = ''): String; inline;
function ToGuid: TGUID; inline;
function ToObjectId: TgoObjectId; inline;
function AsBoolean: Boolean; inline;
function AsInteger: Integer; inline;
function AsInt64: Int64; inline;
function AsDouble: Double; inline;
function AsString: String; inline;
function AsArray: TArray<TgoBsonValue>; inline;
function AsByteArray: TBytes; inline;
function AsGuid: TGUID; inline;
function AsObjectId: TgoObjectId; inline;
function Clone: TgoBsonValue; inline;
function DeepClone: TgoBsonValue; inline;
function ToBson: TBytes; inline;
function ToJson: String; overload; inline;
function ToJson(const ASettings: TgoJsonWriterSettings): String; overload; inline;

Properties

property BsonType: TgoBsonType read GetBsonType;
property IsBoolean: Boolean read GetIsBoolean;
property IsBsonArray: Boolean read GetIsBsonArray;
property IsBsonBinaryData: Boolean read GetIsBsonBinaryData;
property IsBsonDateTime: Boolean read GetIsBsonDateTime;
property IsBsonDocument: Boolean read GetIsBsonDocument;
property IsBsonJavaScript: Boolean read GetIsBsonJavaScript;
property IsBsonJavaScriptWithScope: Boolean read GetIsBsonJavaScriptWithScope;
property IsBsonMaxKey: Boolean read GetIsBsonMaxKey;
property IsBsonMinKey: Boolean read GetIsBsonMinKey;
property IsBsonNull: Boolean read GetIsBsonNull;
property IsBsonRegularExpression: Boolean read GetIsBsonRegularExpression;
property IsBsonSymbol: Boolean read GetIsBsonSymbol;
property IsBsonTimestamp: Boolean read GetIsBsonTimestamp;
property IsBsonUndefined: Boolean read GetIsBsonUndefined;
property IsDateTime: Boolean read GetIsDateTime;
property IsDouble: Boolean read GetIsDouble;
property IsGuid: Boolean read GetIsGuid;
property IsInt32: Boolean read GetIsInt32;
property IsInt64: Boolean read GetIsInt64;
property IsNumeric: Boolean read GetIsNumeric;
property IsObjectId: Boolean read GetIsObjectId;
property IsString: Boolean read GetIsString;

Description

Methods

class function Parse(const AJson: String): TgoBsonValue; static;

Creates a BSON value by paring a JSON string.

Parameters
AJson
the JSON string to parse.
Returns

The BSON value

Exceptions raised
EgoJsonParserError
or EInvalidOperation on parse errors
class function TryParse(const AJson: String; out AValue: TgoBsonValue): Boolean; static;

Tries to parse a JSON string to a BSON value.

Parameters
AJson
the JSON string to parse.
AArray
is set to the parsed JSON on success.
Returns

True if the JSON string could be successfully parsed.

class function Load(const ABson: TBytes): TgoBsonValue; static;

Creates a BSON value from a BSON byte array.

Parameters
ABson
the BSON byte array to load.
Returns

The BSON value

Exceptions raised
EInvalidOperation
if BSON data is invalid
class function TryLoad(const ABson: TBytes; out AValue: TgoBsonValue): Boolean; static;

Tries to load a BSON value from a BSON byte array.

Parameters
ABson
the BSON byte array to load.
AValue
is set to the loaded BSON on success.
Returns

True if the BSON value could be successfully loaded.

class function LoadFromJsonFile(const AFilename: String): TgoBsonValue; static;

Loads a BSON value from a JSON file.

Parameters
AFilename
the name of the JSON file
Returns

The BSON value

Exceptions raised
EgoJsonParserError
or EInvalidOperation on parse errors
class function LoadFromJsonStream(const AStream: TStream): TgoBsonValue; static;

Loads a BSON value from a JSON stream.

Parameters
AStream
the JSON stream
Returns

The BSON value

Exceptions raised
EgoJsonParserError
or EInvalidOperation on parse errors
class function LoadFromBsonFile(const AFilename: String): TgoBsonValue; static;

Loads a BSON value from a BSON file.

Parameters
AFilename
the name of the BSON file
Returns

The BSON value

Exceptions raised
EInvalidOperation
when the BSON file is invalid
class function LoadFromBsonStream(const AStream: TStream): TgoBsonValue; static;

Loads a BSON value from a BSON stream.

Parameters
AStream
the BSON stream
Returns

The BSON value

Exceptions raised
EInvalidOperation
when the BSON file is invalid
procedure SaveToJsonFile(const AFilename: String); overload;

Saves the BSON value to a JSON file.

Parameters
AFilename
the name of the JSON file.
procedure SaveToJsonFile(const AFilename: String; const ASettings: TgoJsonWriterSettings); overload;

Saves the BSON value to a JSON file, using specified settings.

Parameters
AFilename
the name of the JSON file.
ASettings
the output settings to use, such as pretty-printing and Strict vs Shell mode.
procedure SaveToJsonStream(const AStream: TStream); overload;

Saves the BSON value to a JSON stream.

Parameters
AStream
the JSON stream
procedure SaveToJsonStream(const AStream: TStream; const ASettings: TgoJsonWriterSettings); overload;

Saves the BSON value to a JSON stream.

Parameters
AStream
the JSON stream
ASettings
the output settings to use, such as pretty-printing and Strict vs Shell mode.
procedure SaveToBsonFile(const AFilename: String);

Saves the BSON value to a BSON file.

Parameters
AFilename
the name of the BSON file.
procedure SaveToBsonStream(const AStream: TStream);

Saves the BSON value to a BSON stream.

Parameters
AStream
the BSON stream
class operator Implicit(const A: Boolean): TgoBsonValue; static;

Implicitly converts a Boolean to a BSON value

class operator Implicit(const A: Integer): TgoBsonValue; static;

Implicitly converts an Integer to a BSON value

class operator Implicit(const A: Int64): TgoBsonValue; static;

Implicitly converts an Int64 to a BSON value

class operator Implicit(const A: Double): TgoBsonValue; static;

Implicitly converts a Double to a BSON value

class operator Implicit(const A: Extended): TgoBsonValue; static;

Implicitly converts an Extended to a BSON value

class operator Implicit(const A: TDateTime): TgoBsonValue; static;

Implicitly converts a TDateTime a BSON value of type TgoBsonDateTime. The TDateTime value must be UTC format.

class operator Implicit(const A: String): TgoBsonValue; static;

Implicitly converts a String to a BSON value

class operator Implicit(const A: TBytes): TgoBsonValue; static;

Implicitly converts an array of bytes to a BSON value of type TgoBsonBinaryData with sub type Binary.

class operator Implicit(const A: TGUID): TgoBsonValue; static;

Implicitly converts a GUID to a BSON value of type TgoBsonBinaryData with sub type UuidStandard.

class operator Implicit(const A: TgoObjectId): TgoBsonValue; static;

Implicitly converts an ObjectId to a BSON value

class operator Implicit(const A: TgoBsonValue): Boolean; static;

Tries to implicitly convert a BSON value to a Boolean. Depending on the BsonType, one of the following will be returned:

  • Boolean: the value

  • Double: True if the value isn't 0 or NaN

  • Integer: True if the value isn't 0

  • Null: False

  • String: True if the value isn't an empty string

  • Otherwise: True

class operator Implicit(const A: TgoBsonValue): Integer; static;

Tries to implicitly convert a BSON value to an Integer. Depending on the BsonType, one of the following will be returned:

  • Boolean: 0 if False, 1 if True

  • Double: truncated value

  • Integer: the value

  • String: String converted to Integer, if possible

  • Otherwise: 0

class operator Implicit(const A: TgoBsonValue): Int64; static;

Tries to implicitly convert a BSON value to an Int64. Depending on the BsonType, one of the following will be returned:

  • Boolean: 0 if False, 1 if True

  • Double: truncated value

  • Integer: the value

  • String: String converted to Int64, if possible

  • Otherwise: 0

class operator Implicit(const A: TgoBsonValue): UInt64; static;

Tries to implicitly convert a BSON value to an UInt64. Depending on the BsonType, one of the following will be returned:

  • Boolean: 0 if False, 1 if True

  • Double: truncated value

  • Integer: the value

  • String: String converted to UInt64, if possible

  • Otherwise: 0

class operator Implicit(const A: TgoBsonValue): Double; static;

Tries to implicitly convert a BSON value to an Double. Depending on the BsonType, one of the following will be returned:

  • Boolean: 0 if False, 1 if True

  • Double: the value

  • Integer: the value

  • String: String (in US format) converted to Double, if possible

  • Otherwise: 0

class operator Implicit(const A: TgoBsonValue): Extended; static;

Tries to implicitly convert a BSON value to an Extended. Depending on the BsonType, one of the following will be returned:

  • Boolean: 0 if False, 1 if True

  • Double: the value

  • Integer: the value

  • String: String (in US format) converted to Double, if possible

  • Otherwise: 0

class operator Implicit(const A: TgoBsonValue): TDateTime; static;

Tries to implicitly convert a BSON value to a TDateTime in UTC format. Depending on the BsonType, one of the following will be returned:

  • DateTime: the value in UTC format

  • Otherwise: 0

Note: see ToLocalTime and ToUniversalTime for more control over the output.

class operator Implicit(const A: TgoBsonValue): String; static;

Tries to implicitly convert a BSON value to a String. Depending on the BsonType, one of the following will be returned:

  • Boolean: 'false' or 'true'

  • Double: the value converted to a String (in US format)

  • Integer: the value converted to an Integer

  • String: the value

  • DateTime: UTC value in ISO8601 format

  • ObjectId: string representation of the ObjectId

  • Null: 'null'

  • Undefined: 'undefined'

  • MinKey: 'MinKey'

  • MaxKey: 'MaxKey'

  • Symbol: name of the symbol

  • Otherwise: '' (empty string)

class operator Implicit(const A: TgoBsonValue): TBytes; static;

Tries to implicitly convert a BSON value to a byte array. Depending on the BsonType, one of the following will be returned:

  • Binary: the value

  • Otherwise: nil (empty array)

class operator Implicit(const A: TgoBsonValue): TGUID; static;

Tries to implicitly convert a BSON value to a GUID. Depending on the BsonType, one of the following will be returned:

  • Binary of sub type UuidLegacy or UuidStandard: the value

  • Otherwise: TGUID.Empty

class operator Implicit(const A: TgoBsonValue): TgoObjectId; static;

Tries to implicitly convert a BSON value to an ObjectId. Depending on the BsonType, one of the following will be returned:

function ToLocalTime: TDateTime; inline;

Tries to implicitly convert a BSON value to a TDateTime in local time. Depending on the BsonType, one of the following will be returned:

  • DateTime: the value in local time

  • Otherwise: 0

function ToUniversalTime: TDateTime; inline;

Tries to implicitly convert a BSON value to a TDateTime in universal time. Depending on the BsonType, one of the following will be returned:

  • DateTime: the value in universal time (UTC)

  • Otherwise: 0

class operator Equal(const A, B: TgoBsonValue): Boolean; static;

Tests 2 BSON values for equality. BSON values are equal if their types and contents match exactly.

class operator NotEqual(const A, B: TgoBsonValue): Boolean; static;

Tests 2 BSON values for inequality

function IsNil: Boolean; inline;

Checks if the BSON value has been assigned.

Note: does not return True if the value is a NULL value (see IsBsonNull/AsBsonNull)

Returns

True if value hasn't been assigned yet.

procedure SetNil; inline;

Unassigns the BSON value (like setting an object to nil). IsNil will return True afterwards.

function ToBoolean(const ADefault: Boolean = False): Boolean; inline;

Tries to convert the value to a Boolean.

Parameters
ADefault
(optional) value to return if value cannot be converted. Defaults to False.
function ToInteger(const ADefault: Integer = 0): Integer; inline;

Tries to convert the value to a 32-bit integer.

Parameters
ADefault
(optional) value to return if value cannot be converted. Defaults to 0.
function ToInt64(const ADefault: Int64 = 0): Int64; inline;

Tries to convert the value to a 64-bit integer.

Parameters
ADefault
(optional) value to return if value cannot be converted. Defaults to 0.
function ToDouble(const ADefault: Double = 0): Double; inline;

Tries to convert the value to a floating-point number.

Parameters
ADefault
(optional) value to return if value cannot be converted. Defaults to 0.0.
function ToString(const ADefault: String = ''): String; inline;

Tries to convert the value to a string.

Parameters
ADefault
(optional) value to return if value cannot be converted. Defaults to ''.
function ToGuid: TGUID; inline;

Tries to convert the value to a GUID. Returns an empty GUID if the value cannot be converted.

function ToObjectId: TgoObjectId; inline;

Tries to convert the value to an ObjectId. Returns an empty ObjectId if the value cannot be converted.

function AsBoolean: Boolean; inline;

Returns the value as a Boolean.

Exceptions raised
EIntfCastError
if this value isn't a Boolean
function AsInteger: Integer; inline;

Returns the value as a 32-bit integer.

Exceptions raised
EIntfCastError
if this value isn't a 32-bit integer
function AsInt64: Int64; inline;

Returns the value as a 64-bit integer.

Exceptions raised
EIntfCastError
if this value isn't a 64-bit integer
function AsDouble: Double; inline;

Returns the value as a Double.

Exceptions raised
EIntfCastError
if this value isn't a Double
function AsString: String; inline;

Returns the value as a String.

Exceptions raised
EIntfCastError
if this value isn't a String
function AsArray: TArray<TgoBsonValue>; inline;

Returns the value as a Delphi array of BSON values.

Exceptions raised
EIntfCastError
if this value isn't a BSON array
function AsByteArray: TBytes; inline;

Returns the value as an array of bytes.

Exceptions raised
EIntfCastError
if this value isn't a Binary value
function AsGuid: TGUID; inline;

Returns the value as a GUID.

Exceptions raised
EIntfCastError
if this value isn't a Binary value of sub type UuidLegacy or UuidStandard.
function AsObjectId: TgoObjectId; inline;

Returns the value as an ObjectId.

Exceptions raised
EIntfCastError
if this value isn't an ObjectId
function Clone: TgoBsonValue; inline;

Creates shallow clone of the value.

Note: a shallow clone copies the value, but not any sub-values. For example, if the value is an array, then the array reference is copied, but not the individual elements.

Returns

The shallow clone

function DeepClone: TgoBsonValue; inline;

Creates deep clone of the value.

Note: a deep clone copies the value and any sub-values it may hold. For example, if the value is an array, then the array reference is copied, and its individual elements are copied as well. Any sub-values of those elements are also copied, etc...

Returns

The deep clone

function ToBson: TBytes; inline;

Saves the value to a BSON-compliant byte stream.

Returns

The BSON byte stream.

function ToJson: String; overload; inline;

Saves the value to a string in JSON format.

Note: the value is saved using the default writer settings. That is, without any pretty printing, and in Strict mode. Use the other overload of this function to specify output settings.

Returns

The value in JSON format.

function ToJson(const ASettings: TgoJsonWriterSettings): String; overload; inline;

Saves the value to a string in JSON format, using specified settings.

Parameters
ASettings
the output settings to use, such as pretty-printing and Strict vs Shell mode.
Returns

The value in JSON format.

Properties

property BsonType: TgoBsonType read GetBsonType;

The type of this value.

property IsBoolean: Boolean read GetIsBoolean;

Whether this value represents a Boolean.

property IsBsonArray: Boolean read GetIsBsonArray;

Whether this value represents a BSON array.

property IsBsonBinaryData: Boolean read GetIsBsonBinaryData;

Whether this value represents a BSON binary value.

property IsBsonDateTime: Boolean read GetIsBsonDateTime;

Whether this value represents a BSON DateTime.

property IsBsonDocument: Boolean read GetIsBsonDocument;

Whether this value represents a BSON Document (aka Dictionary or Object).

property IsBsonJavaScript: Boolean read GetIsBsonJavaScript;

Whether this value represents a JavaScript script.

property IsBsonJavaScriptWithScope: Boolean read GetIsBsonJavaScriptWithScope;

Whether this value represents a JavaScript script with scope.

property IsBsonMaxKey: Boolean read GetIsBsonMaxKey;

Whether this value represents a BSON MaxKey value.

property IsBsonMinKey: Boolean read GetIsBsonMinKey;

Whether this value represents a BSON MinKey value.

property IsBsonNull: Boolean read GetIsBsonNull;

Whether this value represents a BSON Null value.

property IsBsonRegularExpression: Boolean read GetIsBsonRegularExpression;

Whether this value represents a regular expression.

property IsBsonSymbol: Boolean read GetIsBsonSymbol;

Whether this value represents a (deprectated) BSON symbol.

property IsBsonTimestamp: Boolean read GetIsBsonTimestamp;

Whether this value represents a BSON timestamp.

property IsBsonUndefined: Boolean read GetIsBsonUndefined;

Whether this value represents a BSON Undefined value.

property IsDateTime: Boolean read GetIsDateTime;

Whether this value represents a DateTime value.

property IsDouble: Boolean read GetIsDouble;

Whether this value represents a Double.

property IsGuid: Boolean read GetIsGuid;

Whether this value represents a GUID.

property IsInt32: Boolean read GetIsInt32;

Whether this value represents a 32-bit integer.

property IsInt64: Boolean read GetIsInt64;

Whether this value represents a 64-bit integer.

property IsNumeric: Boolean read GetIsNumeric;

Whether this value represents a numeric value (Integer or Double).

property IsObjectId: Boolean read GetIsObjectId;

Whether this value represents an ObjectId.

property IsString: Boolean read GetIsString;

Whether this value represents a String.


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