MCPcopy Create free account
hub / github.com/Effect-TS/effect / decodeRange

Function decodeRange

packages/sql/pg/src/PgTypes.ts:1929–1964  ·  view source on GitHub ↗
(
  bytes: Uint8Array,
  start: number,
  size: number,
  subtypeOid: number,
  lookup: Lookup
)

Source from the content-addressed store, hash-verified

1927}
1928
1929const decodeRange = (
1930 bytes: Uint8Array,
1931 start: number,
1932 size: number,
1933 subtypeOid: number,
1934 lookup: Lookup
1935): Range<unknown> => {
1936 if (size < 1) return fail("Truncated range value")
1937 const flags = bytes[start]
1938 // An empty range has no bounds, whatever its other flags say.
1939 const hasLower = (flags & (RANGE_EMPTY | RANGE_LB_INF)) === 0
1940 const hasUpper = (flags & (RANGE_EMPTY | RANGE_UB_INF)) === 0
1941 const codec = requireCodec(subtypeOid, lookup)
1942 const limit = start + size
1943 let offset = start + 1
1944 let lower: unknown = null
1945 let upper: unknown = null
1946 if (hasLower) {
1947 const boundSize = frameSize(bytes, offset, limit, "range bound")
1948 lower = readWith(codec, bytes, offset + 4, boundSize)
1949 offset += 4 + boundSize
1950 }
1951 if (hasUpper) {
1952 const boundSize = frameSize(bytes, offset, limit, "range bound")
1953 upper = readWith(codec, bytes, offset + 4, boundSize)
1954 offset += 4 + boundSize
1955 }
1956 if (offset !== limit) return fail("Range value has trailing bytes")
1957 return {
1958 lower,
1959 upper,
1960 lowerInclusive: hasLower && (flags & RANGE_LB_INC) !== 0,
1961 upperInclusive: hasUpper && (flags & RANGE_UB_INC) !== 0,
1962 empty: (flags & RANGE_EMPTY) !== 0
1963 }
1964}
1965
1966/**
1967 * PostgreSQL multirange_send: an int32 count, then an int32 length and range

Callers 1

makeRangeCodecFunction · 0.85

Calls 4

requireCodecFunction · 0.85
frameSizeFunction · 0.85
readWithFunction · 0.85
failFunction · 0.70

Tested by

no test coverage detected